Mercurial > hg > nsaunier > traffic-intelligence
comparison c/test_graph.cpp @ 362:cc8e54997d4c
corrected error in tests and changed sstream to ostream for FeatureTrajectory operator<<
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Fri, 12 Jul 2013 00:22:09 -0400 |
| parents | 249d65ff6c35 |
| children | 03dbecd3a887 |
comparison
equal
deleted
inserted
replaced
| 361:9d486af42e49 | 362:cc8e54997d4c |
|---|---|
| 9 | 9 |
| 10 using namespace std; | 10 using namespace std; |
| 11 using namespace cv; | 11 using namespace cv; |
| 12 | 12 |
| 13 TEST_CASE("graph/connected_components", "test graph connected components") { | 13 TEST_CASE("graph/connected_components", "test graph connected components") { |
| 14 FeatureGraph featureGraph(5, 1, 5 , 1.); // (float _connectionDistance, float _segmentationDistance, unsigned int _minFeatureTime, float _minNFeaturesPerGroup) | 14 float connectionDistance = 5.; |
| 15 unsigned int lastInstant = 20; | 15 float segmentationDistance = 1.; |
| 16 FeatureTrajectoryPtr ft1 = createFeatureTrajectory(1, 10, lastInstant, Point2f(1,1), Point2f(0.5, 0.)); | 16 unsigned int minFeatureTime = 5; |
| 17 FeatureTrajectoryPtr ft2 = createFeatureTrajectory(2, 10, lastInstant, Point2f(1.1,1), Point2f(0.5, 0.)); | 17 float minNFeaturesPerGroup = 0.99; |
| 18 FeatureGraph featureGraph(connectionDistance, segmentationDistance, minFeatureTime, minNFeaturesPerGroup); | |
| 19 unsigned int firstInstant = 10, lastInstant = 20; | |
| 20 FeatureTrajectoryPtr ft1 = createFeatureTrajectory(1, firstInstant, lastInstant, Point2f(1,1), Point2f(0.5, 0.)); | |
| 21 FeatureTrajectoryPtr ft2 = createFeatureTrajectory(2, firstInstant, lastInstant, Point2f(1.1,1), Point2f(0.5, 0.)); | |
| 18 | 22 |
| 19 featureGraph.addFeature(ft1); | 23 featureGraph.addFeature(ft1); |
| 20 REQUIRE(featureGraph.getNVertices() == 1); | 24 REQUIRE(featureGraph.getNVertices() == 1); |
| 21 REQUIRE(featureGraph.getNEdges() == 0); | 25 REQUIRE(featureGraph.getNEdges() == 0); |
| 22 | 26 |
| 38 REQUIRE(featureGraph.getNEdges() == 0); | 42 REQUIRE(featureGraph.getNEdges() == 0); |
| 39 | 43 |
| 40 // test connection distance | 44 // test connection distance |
| 41 featureGraph.addFeature(ft1); | 45 featureGraph.addFeature(ft1); |
| 42 featureGraph.addFeature(ft2); | 46 featureGraph.addFeature(ft2); |
| 43 FeatureTrajectoryPtr ft3 = createFeatureTrajectory(3, 10, lastInstant, Point2f(6.05,1), Point2f(0.5, 0.)); // connected to ft2 only | 47 FeatureTrajectoryPtr ft3 = createFeatureTrajectory(3, firstInstant, lastInstant, Point2f(6.05,1), Point2f(0.5, 0.)); // connected to ft2 only |
| 44 featureGraph.addFeature(ft3); | 48 featureGraph.addFeature(ft3); |
| 45 FeatureTrajectoryPtr ft4 = createFeatureTrajectory(4, 10, lastInstant, Point2f(11.1,1), Point2f(0.5, 0.)); // not connected | 49 FeatureTrajectoryPtr ft4 = createFeatureTrajectory(4, firstInstant, lastInstant, Point2f(11.1,1), Point2f(0.5, 0.)); // not connected |
| 46 featureGraph.addFeature(ft4); | 50 featureGraph.addFeature(ft4); |
| 47 | 51 |
| 52 REQUIRE(ft1->minMaxSimilarity(*ft2, firstInstant, lastInstant, connectionDistance, segmentationDistance)); | |
| 53 REQUIRE(ft2->minMaxSimilarity(*ft3, firstInstant, lastInstant, connectionDistance, segmentationDistance)); | |
| 54 REQUIRE_FALSE(ft1->minMaxSimilarity(*ft3, firstInstant, lastInstant, connectionDistance, segmentationDistance)); | |
| 55 REQUIRE_FALSE(ft1->minMaxSimilarity(*ft4, firstInstant, lastInstant, connectionDistance, segmentationDistance)); | |
| 56 REQUIRE_FALSE(ft2->minMaxSimilarity(*ft4, firstInstant, lastInstant, connectionDistance, segmentationDistance)); | |
| 57 REQUIRE_FALSE(ft3->minMaxSimilarity(*ft4, firstInstant, lastInstant, connectionDistance, segmentationDistance)); | |
| 58 | |
| 48 REQUIRE(featureGraph.getNVertices() == 4); | 59 REQUIRE(featureGraph.getNVertices() == 4); |
| 49 REQUIRE(featureGraph.getNEdges() == 2); | 60 REQUIRE(featureGraph.getNEdges() == 2); |
| 50 | 61 |
| 51 featureGraph.connectedComponents(lastInstant+1); | 62 featureGraph.connectedComponents(lastInstant+1); |
| 52 components = featureGraph.getFeatureGroups(); | 63 components = featureGraph.getFeatureGroups(); |
