Mercurial > hg > nsaunier > traffic-intelligence
annotate include/testutils.hpp @ 372:349eb1e09f45
Cleaned the methods/functions indicating if a point is in a polygon
In general, shapely should be used, especially for lots of points:
from shapely.geometry import Polygon, Point
poly = Polygon(array([[0,0],[0,1],[1,1],[1,0]]))
p = Point(0.5,0.5)
poly.contains(p) -> returns True
poly.contains(Point(-1,-1)) -> returns False
You can convert a moving.Point to a shapely point: p = moving.Point(1,2) p.asShapely() returns the equivalent shapely point
If you have several points to test, use moving.pointsInPolygon(points, polygon) where points are moving.Point and polygon is a shapely polygon.
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Tue, 16 Jul 2013 17:00:17 -0400 |
| parents | f7ddfc4aeb1e |
| children | 045d05cef9d0 |
| rev | line source |
|---|---|
|
196
aeab0b88c9b6
began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
1 #ifndef TEST_UTILS_HPP |
|
aeab0b88c9b6
began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
2 #define TEST_UTILS_HPP |
|
aeab0b88c9b6
began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
3 |
|
aeab0b88c9b6
began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
4 #include "Motion.hpp" |
|
aeab0b88c9b6
began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
5 |
|
aeab0b88c9b6
began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
6 #include "opencv2/core/core.hpp" |
|
aeab0b88c9b6
began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
7 |
|
aeab0b88c9b6
began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
8 #include <boost/shared_ptr.hpp> |
|
aeab0b88c9b6
began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
9 |
|
201
f7ddfc4aeb1e
added tests for graphs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
196
diff
changeset
|
10 inline boost::shared_ptr<FeatureTrajectory> createFeatureTrajectory(const unsigned int& id, const unsigned int& firstInstant, const unsigned int& lastInstant, const cv::Point2f& firstPosition, const cv::Point2f& velocity) { |
|
196
aeab0b88c9b6
began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
11 cv::Mat emptyHomography; |
|
aeab0b88c9b6
began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
12 boost::shared_ptr<FeatureTrajectory> t = boost::shared_ptr<FeatureTrajectory>(new FeatureTrajectory(firstInstant, firstPosition, emptyHomography)); |
|
aeab0b88c9b6
began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
13 cv::Point2f p = firstPosition; |
|
201
f7ddfc4aeb1e
added tests for graphs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
196
diff
changeset
|
14 for (unsigned int i=firstInstant+1; i<=lastInstant; ++i) { |
|
196
aeab0b88c9b6
began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
15 p = p+velocity; |
|
aeab0b88c9b6
began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
16 t->addPoint(i, p, emptyHomography); |
|
aeab0b88c9b6
began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
17 } |
|
201
f7ddfc4aeb1e
added tests for graphs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
196
diff
changeset
|
18 t->setId(id); |
|
196
aeab0b88c9b6
began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
19 return t; |
|
aeab0b88c9b6
began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
20 } |
|
aeab0b88c9b6
began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
21 |
|
aeab0b88c9b6
began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
22 #endif |
