Mercurial > hg > nsaunier > traffic-intelligence
comparison c/test_graph.cpp @ 614:5e09583275a4
Merged Nicolas/trafficintelligence into default
| author | Mohamed Gomaa <eng.m.gom3a@gmail.com> |
|---|---|
| date | Fri, 05 Dec 2014 12:13:53 -0500 |
| parents | 03dbecd3a887 |
| children | 05ccd8ef150c |
comparison
equal
deleted
inserted
replaced
| 598:11f96bd08552 | 614:5e09583275a4 |
|---|---|
| 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 |
| 23 featureGraph.addFeature(ft2); | 27 featureGraph.addFeature(ft2); |
| 24 REQUIRE(featureGraph.getNVertices() == 2); | 28 REQUIRE(featureGraph.getNVertices() == 2); |
| 25 REQUIRE(featureGraph.getNEdges() == 1); | 29 REQUIRE(featureGraph.getNEdges() == 1); |
| 26 | 30 |
| 27 featureGraph.connectedComponents(lastInstant); | 31 featureGraph.connectedComponents(lastInstant); |
| 28 vector<vector<unsigned int> > components = featureGraph.getFeatureGroups(); | 32 vector<vector<FeatureTrajectoryPtr> > components; |
| 33 featureGraph.getFeatureGroups(components); | |
| 29 REQUIRE(components.size() == 0); | 34 REQUIRE(components.size() == 0); |
| 30 REQUIRE(featureGraph.getNVertices() == 2); | 35 REQUIRE(featureGraph.getNVertices() == 2); |
| 31 REQUIRE(featureGraph.getNEdges() == 1); | 36 REQUIRE(featureGraph.getNEdges() == 1); |
| 32 | 37 |
| 33 featureGraph.connectedComponents(lastInstant+1); | 38 featureGraph.connectedComponents(lastInstant+1); |
| 34 components = featureGraph.getFeatureGroups(); | 39 featureGraph.getFeatureGroups(components); |
| 35 REQUIRE(components.size() == 1); | 40 REQUIRE(components.size() == 1); |
| 36 REQUIRE(components[0].size() == 2); | 41 REQUIRE(components[0].size() == 2); |
| 37 REQUIRE(featureGraph.getNVertices() == 0); | 42 REQUIRE(featureGraph.getNVertices() == 0); |
| 38 REQUIRE(featureGraph.getNEdges() == 0); | 43 REQUIRE(featureGraph.getNEdges() == 0); |
| 39 | 44 |
| 40 // test connection distance | 45 // test connection distance |
| 41 featureGraph.addFeature(ft1); | 46 featureGraph.addFeature(ft1); |
| 42 featureGraph.addFeature(ft2); | 47 featureGraph.addFeature(ft2); |
| 43 FeatureTrajectoryPtr ft3 = createFeatureTrajectory(3, 10, lastInstant, Point2f(6.05,1), Point2f(0.5, 0.)); // connected to ft2 only | 48 FeatureTrajectoryPtr ft3 = createFeatureTrajectory(3, firstInstant, lastInstant, Point2f(6.05,1), Point2f(0.5, 0.)); // connected to ft2 only |
| 44 featureGraph.addFeature(ft3); | 49 featureGraph.addFeature(ft3); |
| 45 FeatureTrajectoryPtr ft4 = createFeatureTrajectory(4, 10, lastInstant, Point2f(11.1,1), Point2f(0.5, 0.)); // not connected | 50 FeatureTrajectoryPtr ft4 = createFeatureTrajectory(4, firstInstant, lastInstant, Point2f(11.1,1), Point2f(0.5, 0.)); // not connected |
| 46 featureGraph.addFeature(ft4); | 51 featureGraph.addFeature(ft4); |
| 47 | 52 |
| 53 REQUIRE(ft1->minMaxSimilarity(*ft2, firstInstant, lastInstant, connectionDistance, segmentationDistance)); | |
| 54 REQUIRE(ft2->minMaxSimilarity(*ft3, firstInstant, lastInstant, connectionDistance, segmentationDistance)); | |
| 55 REQUIRE_FALSE(ft1->minMaxSimilarity(*ft3, firstInstant, lastInstant, connectionDistance, segmentationDistance)); | |
| 56 REQUIRE_FALSE(ft1->minMaxSimilarity(*ft4, firstInstant, lastInstant, connectionDistance, segmentationDistance)); | |
| 57 REQUIRE_FALSE(ft2->minMaxSimilarity(*ft4, firstInstant, lastInstant, connectionDistance, segmentationDistance)); | |
| 58 REQUIRE_FALSE(ft3->minMaxSimilarity(*ft4, firstInstant, lastInstant, connectionDistance, segmentationDistance)); | |
| 59 | |
| 48 REQUIRE(featureGraph.getNVertices() == 4); | 60 REQUIRE(featureGraph.getNVertices() == 4); |
| 49 REQUIRE(featureGraph.getNEdges() == 2); | 61 REQUIRE(featureGraph.getNEdges() == 2); |
| 50 | 62 |
| 51 featureGraph.connectedComponents(lastInstant+1); | 63 featureGraph.connectedComponents(lastInstant+1); |
| 52 components = featureGraph.getFeatureGroups(); | 64 featureGraph.getFeatureGroups(components); |
| 53 REQUIRE(components.size() == 2); | 65 REQUIRE(components.size() == 2); |
| 54 REQUIRE(components[0].size() == 3); | 66 REQUIRE(components[0].size() == 3); |
| 55 REQUIRE(components[1].size() == 1); | 67 REQUIRE(components[1].size() == 1); |
| 56 REQUIRE(featureGraph.getNVertices() == 0); | 68 REQUIRE(featureGraph.getNVertices() == 0); |
| 57 REQUIRE(featureGraph.getNEdges() == 0); | 69 REQUIRE(featureGraph.getNEdges() == 0); |
