Mercurial Hosting > traffic-intelligence
changeset 201:f7ddfc4aeb1e
added tests for graphs
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 05 Mar 2012 01:52:56 -0500 |
parents | 0a27fa343257 |
children | b0b964ba9489 |
files | c/Motion.cpp c/test_feature.cpp c/test_graph.cpp include/Motion.hpp include/testutils.hpp |
diffstat | 5 files changed, 65 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/c/Motion.cpp Fri Mar 02 19:32:54 2012 -0500 +++ b/c/Motion.cpp Mon Mar 05 01:52:56 2012 -0500 @@ -84,7 +84,7 @@ minDistance = distance; else if (distance > maxDistance) maxDistance = distance; - connected = connected && (maxDistance-minDistance < segmentationDistance); + connected = connected && (maxDistance-minDistance <= segmentationDistance); t++; } @@ -177,10 +177,10 @@ property_map<UndirectedGraph, int VertexInformation::*>::type components = get(&VertexInformation::index, graph); int num = connected_components(graph, components, vertex_index_map(get(&VertexInformation::index, graph))); - cout << "Total number of components: " << num << endl; + cout << "last instant threshold " << lastInstant << " Total number of components: " << num << endl; - vector<unsigned int> lastInstants(num, 0); - vector<vector<vertex_descriptor> > tmpobjects(num), objects; + vector<unsigned int> lastInstants(num, 0); // last instant of component with id + vector<vector<vertex_descriptor> > tmpobjects(num), objects; // vector of components (component = vector of vertex descriptors) graph_traits<UndirectedGraph>::vertex_iterator vi, vend; for(tie(vi,vend) = vertices(graph); vi != vend; ++vi) {
--- a/c/test_feature.cpp Fri Mar 02 19:32:54 2012 -0500 +++ b/c/test_feature.cpp Mon Mar 05 01:52:56 2012 -0500 @@ -1,15 +1,31 @@ #define BOOST_TEST_MODULE traffic intelligence +#include "Motion.hpp" +#include "testutils.hpp" + +#include "opencv2/core/core.hpp" + #include <boost/test/unit_test.hpp> #include <boost/test/floating_point_comparison.hpp> using namespace std; +using namespace cv; BOOST_AUTO_TEST_SUITE(test_feature) -BOOST_AUTO_TEST_CASE(feature_stationary) { - int i=5; - BOOST_CHECK_EQUAL(i, 5); +BOOST_AUTO_TEST_CASE(feature_similarity) { + FeatureTrajectoryPtr ft1 = createFeatureTrajectory(1, 10, 20, Point2f(1,1), Point2f(0, 1)); + FeatureTrajectoryPtr ft2 = createFeatureTrajectory(2, 10, 20, Point2f(2,1), Point2f(0, 1)); + + BOOST_CHECK(!ft1->minMaxSimilarity(*ft2, 10, 20, 0.5, 0.1)); + BOOST_CHECK(ft1->minMaxSimilarity(*ft2, 10, 20, 1, 0.1)); + + ft2 = createFeatureTrajectory(2, 10, 19, Point2f(1,1), Point2f(0, 1)); + Mat homography; + ft2->addPoint(20, Point2f(1,11.5), homography); + + BOOST_CHECK(!ft1->minMaxSimilarity(*ft2, 10, 20, 0, 0.4)); + BOOST_CHECK(ft1->minMaxSimilarity(*ft2, 10, 20, 0, 0.5)); } BOOST_AUTO_TEST_SUITE_END()
--- a/c/test_graph.cpp Fri Mar 02 19:32:54 2012 -0500 +++ b/c/test_graph.cpp Mon Mar 05 01:52:56 2012 -0500 @@ -6,15 +6,18 @@ #include <boost/test/unit_test.hpp> #include <boost/test/floating_point_comparison.hpp> +#include <iostream> + using namespace std; using namespace cv; BOOST_AUTO_TEST_SUITE(test_graph) -BOOST_AUTO_TEST_CASE(graph_add_delete) { - FeatureGraph featureGraph(5, 1, 5 /* min time interval */, 1.); - FeatureTrajectoryPtr ft1 = createFeatureTrajectory(10, 20, Point2f(1,1), Point2f(0.5, 0.)); - FeatureTrajectoryPtr ft2 = createFeatureTrajectory(10, 20, Point2f(1.1,1), Point2f(0.5, 0.)); +BOOST_AUTO_TEST_CASE(graph_add_connected_components) { + FeatureGraph featureGraph(5, 1, 5 , 1.); // (float _connectionDistance, float _segmentationDistance, unsigned int _minFeatureTime, float _minNFeaturesPerGroup) + unsigned int lastInstant = 20; + FeatureTrajectoryPtr ft1 = createFeatureTrajectory(1, 10, lastInstant, Point2f(1,1), Point2f(0.5, 0.)); + FeatureTrajectoryPtr ft2 = createFeatureTrajectory(2, 10, lastInstant, Point2f(1.1,1), Point2f(0.5, 0.)); featureGraph.addFeature(ft1); BOOST_CHECK_EQUAL(featureGraph.getNVertices(), 1); @@ -24,7 +27,37 @@ BOOST_CHECK_EQUAL(featureGraph.getNVertices(), 2); BOOST_CHECK_EQUAL(featureGraph.getNEdges(), 1); - + featureGraph.connectedComponents(lastInstant); + vector<vector<unsigned int> > components = featureGraph.getFeatureGroups(); + BOOST_CHECK_EQUAL(components.size(), 0); + BOOST_CHECK_EQUAL(featureGraph.getNVertices(), 2); + BOOST_CHECK_EQUAL(featureGraph.getNEdges(), 1); + + featureGraph.connectedComponents(lastInstant+1); + components = featureGraph.getFeatureGroups(); + BOOST_CHECK_EQUAL(components.size(), 1); + BOOST_CHECK_EQUAL(components[0].size(), 2); + BOOST_CHECK_EQUAL(featureGraph.getNVertices(), 0); + BOOST_CHECK_EQUAL(featureGraph.getNEdges(), 0); + + // test connection distance + featureGraph.addFeature(ft1); + featureGraph.addFeature(ft2); + FeatureTrajectoryPtr ft3 = createFeatureTrajectory(3, 10, lastInstant, Point2f(6.05,1), Point2f(0.5, 0.)); // connected to ft2 only + featureGraph.addFeature(ft3); + FeatureTrajectoryPtr ft4 = createFeatureTrajectory(4, 10, lastInstant, Point2f(11.1,1), Point2f(0.5, 0.)); // not connected + featureGraph.addFeature(ft4); + + BOOST_CHECK_EQUAL(featureGraph.getNVertices(), 4); + BOOST_CHECK_EQUAL(featureGraph.getNEdges(), 2); + + featureGraph.connectedComponents(lastInstant+1); + components = featureGraph.getFeatureGroups(); + BOOST_CHECK_EQUAL(components.size(), 2); + BOOST_CHECK_EQUAL(components[0].size(), 3); + BOOST_CHECK_EQUAL(components[1].size(), 1); + BOOST_CHECK_EQUAL(featureGraph.getNVertices(), 0); + BOOST_CHECK_EQUAL(featureGraph.getNEdges(), 0); } BOOST_AUTO_TEST_SUITE_END()
--- a/include/Motion.hpp Fri Mar 02 19:32:54 2012 -0500 +++ b/include/Motion.hpp Mon Mar 05 01:52:56 2012 -0500 @@ -116,8 +116,7 @@ void connectedComponents(const int& lastInstant); /** Performs some checks on groups of features and return their lists of ids if correct - Removes the vertices from the graph - */ + Removes the vertices from the graph */ std::vector<std::vector<unsigned int> > getFeatureGroups(void); std::string informationString(void) const;
--- a/include/testutils.hpp Fri Mar 02 19:32:54 2012 -0500 +++ b/include/testutils.hpp Mon Mar 05 01:52:56 2012 -0500 @@ -7,14 +7,15 @@ #include <boost/shared_ptr.hpp> -inline boost::shared_ptr<FeatureTrajectory> createFeatureTrajectory(const int& firstInstant, const int& lastInstant, const cv::Point2f& firstPosition, const cv::Point2f& velocity) { +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) { cv::Mat emptyHomography; boost::shared_ptr<FeatureTrajectory> t = boost::shared_ptr<FeatureTrajectory>(new FeatureTrajectory(firstInstant, firstPosition, emptyHomography)); cv::Point2f p = firstPosition; - for (int i=firstInstant+1; i<=lastInstant; ++i) { + for (unsigned int i=firstInstant+1; i<=lastInstant; ++i) { p = p+velocity; t->addPoint(i, p, emptyHomography); } + t->setId(id); return t; }