Mercurial > hg > nsaunier > traffic-intelligence
annotate c/test_feature.cpp @ 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 | f0f800b95765 |
| children | b6ad86ee7033 |
| rev | line source |
|---|---|
|
220
f0f800b95765
switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
201
diff
changeset
|
1 #define CATCH_CONFIG_MAIN |
|
162
61fd5aff418c
added basics to run tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
2 |
|
201
f7ddfc4aeb1e
added tests for graphs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
196
diff
changeset
|
3 #include "Motion.hpp" |
|
f7ddfc4aeb1e
added tests for graphs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
196
diff
changeset
|
4 #include "testutils.hpp" |
|
f7ddfc4aeb1e
added tests for graphs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
196
diff
changeset
|
5 |
|
f7ddfc4aeb1e
added tests for graphs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
196
diff
changeset
|
6 #include "opencv2/core/core.hpp" |
|
f7ddfc4aeb1e
added tests for graphs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
196
diff
changeset
|
7 |
|
220
f0f800b95765
switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
201
diff
changeset
|
8 #include "catch.hpp" |
|
162
61fd5aff418c
added basics to run tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
9 |
|
61fd5aff418c
added basics to run tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
10 using namespace std; |
|
201
f7ddfc4aeb1e
added tests for graphs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
196
diff
changeset
|
11 using namespace cv; |
|
162
61fd5aff418c
added basics to run tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
12 |
|
220
f0f800b95765
switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
201
diff
changeset
|
13 TEST_CASE("features/similarity", "test feature similarity measure") { |
|
201
f7ddfc4aeb1e
added tests for graphs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
196
diff
changeset
|
14 FeatureTrajectoryPtr ft1 = createFeatureTrajectory(1, 10, 20, Point2f(1,1), Point2f(0, 1)); |
|
f7ddfc4aeb1e
added tests for graphs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
196
diff
changeset
|
15 FeatureTrajectoryPtr ft2 = createFeatureTrajectory(2, 10, 20, Point2f(2,1), Point2f(0, 1)); |
|
f7ddfc4aeb1e
added tests for graphs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
196
diff
changeset
|
16 |
|
220
f0f800b95765
switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
201
diff
changeset
|
17 REQUIRE_FALSE(ft1->minMaxSimilarity(*ft2, 10, 20, 0.5, 0.1)); |
|
f0f800b95765
switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
201
diff
changeset
|
18 REQUIRE(ft1->minMaxSimilarity(*ft2, 10, 20, 1, 0.1)); |
|
201
f7ddfc4aeb1e
added tests for graphs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
196
diff
changeset
|
19 |
|
f7ddfc4aeb1e
added tests for graphs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
196
diff
changeset
|
20 ft2 = createFeatureTrajectory(2, 10, 19, Point2f(1,1), Point2f(0, 1)); |
|
f7ddfc4aeb1e
added tests for graphs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
196
diff
changeset
|
21 Mat homography; |
|
f7ddfc4aeb1e
added tests for graphs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
196
diff
changeset
|
22 ft2->addPoint(20, Point2f(1,11.5), homography); |
|
f7ddfc4aeb1e
added tests for graphs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
196
diff
changeset
|
23 |
|
220
f0f800b95765
switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
201
diff
changeset
|
24 REQUIRE_FALSE(ft1->minMaxSimilarity(*ft2, 10, 20, 0, 0.4)); |
|
f0f800b95765
switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
201
diff
changeset
|
25 REQUIRE(ft1->minMaxSimilarity(*ft2, 10, 20, 0, 0.5)); |
|
162
61fd5aff418c
added basics to run tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
26 } |
