Mercurial Hosting > traffic-intelligence
changeset 200:0a27fa343257
added one test and cleaned the first and last instant mess
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 02 Mar 2012 19:32:54 -0500 |
parents | ca9d9104afba |
children | f7ddfc4aeb1e |
files | c/Makefile c/Motion.cpp c/test_graph.cpp include/Motion.hpp |
diffstat | 4 files changed, 26 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/c/Makefile Mon Feb 20 19:32:27 2012 -0500 +++ b/c/Makefile Fri Mar 02 19:32:54 2012 -0500 @@ -27,7 +27,7 @@ OPENCV_HOME=/usr/local INCLUDE+= -I$(OPENCV_HOME)/include -I$(OPENCV_HOME)/include/opencv LIBS += -L$(OPENCV_HOME)/lib - LINUX_BOOST_PREFIX = /usr + LINUX_BOOST_PREFIX = /usr/local CFLAGS += -DLINUX EXE_EXTENSION='' else # windows
--- a/c/Motion.cpp Mon Feb 20 19:32:27 2012 -0500 +++ b/c/Motion.cpp Fri Mar 02 19:32:54 2012 -0500 @@ -20,17 +20,17 @@ /******************** FeatureTrajectory ********************/ -FeatureTrajectory::FeatureTrajectory(const int& frameNum, const cv::Point2f& p, const Mat& homography) - : lost(false) { +FeatureTrajectory::FeatureTrajectory(const unsigned int& frameNum, const cv::Point2f& p, const Mat& homography) + : firstInstant(frameNum), lastInstant(frameNum) { positions = TrajectoryPoint2fPtr(new TrajectoryPoint2f()); velocities = TrajectoryPoint2fPtr(new TrajectoryPoint2f()); addPoint(frameNum, p, homography); } -FeatureTrajectory::FeatureTrajectory(TrajectoryPoint2fPtr& _positions, TrajectoryPoint2fPtr& _velocities) - : lost(false) { +FeatureTrajectory::FeatureTrajectory(TrajectoryPoint2fPtr& _positions, TrajectoryPoint2fPtr& _velocities) { positions = _positions; velocities = _velocities; + positions->computeInstants(firstInstant, lastInstant); } FeatureTrajectory::FeatureTrajectory(const int& id, TrajectoryDBAccessList<Point2f>& trajectoryDB, const string& positionsTableName, const string& velocitiesTableName) { @@ -91,11 +91,15 @@ return connected; } -void FeatureTrajectory::addPoint(const int& frameNum, const Point2f& p, const Mat& homography) { +void FeatureTrajectory::addPoint(const unsigned int& frameNum, const Point2f& p, const Mat& homography) { Point2f pp = p; if (!homography.empty()) pp = project(p, homography); positions->add(frameNum, pp); + if (frameNum < firstInstant) + firstInstant = frameNum; + if (frameNum > lastInstant) + lastInstant = frameNum; computeMotionData(frameNum); assert(positions.size() == displacementDistances.size()+1); assert(positions.size() == velocities.size()+1); @@ -153,14 +157,16 @@ for (graph_traits<UndirectedGraph>::vertex_iterator vi = vertices(graph).first; vi!=vertices(graph).second; ++vi) { // vi pointer to vertex_descriptor FeatureTrajectoryPtr ft2 = graph[*vi].feature; - int lastInstant = static_cast<int>(min(ft->getLastInstant(), ft2->getLastInstant())); - int firstInstant = static_cast<int>(max(ft->getFirstInstant(), ft2->getFirstInstant())); - if (lastInstant-firstInstant > static_cast<int>(minFeatureTime)) { // equivalent to lastInstant-firstInstant+1 >= minFeatureTime - if (ft->minMaxSimilarity(*ft2, firstInstant, lastInstant, connectionDistance, segmentationDistance)) { - UndirectedGraph::edge_descriptor e; - bool unused; - tie(e, unused) = add_edge(newVertex, *vi, graph); - // no need to add measures to graph[e] (edge properties) + if (newVertex != *vi) { + int lastInstant = static_cast<int>(min(ft->getLastInstant(), ft2->getLastInstant())); + int firstInstant = static_cast<int>(max(ft->getFirstInstant(), ft2->getFirstInstant())); + if (lastInstant-firstInstant > static_cast<int>(minFeatureTime)) { // equivalent to lastInstant-firstInstant+1 >= minFeatureTime + if (ft->minMaxSimilarity(*ft2, firstInstant, lastInstant, connectionDistance, segmentationDistance)) { + UndirectedGraph::edge_descriptor e; + bool unused; + tie(e, unused) = add_edge(newVertex, *vi, graph); + // no need to add measures to graph[e] (edge properties) + } } } }
--- a/c/test_graph.cpp Mon Feb 20 19:32:27 2012 -0500 +++ b/c/test_graph.cpp Fri Mar 02 19:32:54 2012 -0500 @@ -12,7 +12,7 @@ BOOST_AUTO_TEST_SUITE(test_graph) BOOST_AUTO_TEST_CASE(graph_add_delete) { - FeatureGraph featureGraph(5, 1, 5, 1.); + 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.)); @@ -20,9 +20,9 @@ BOOST_CHECK_EQUAL(featureGraph.getNVertices(), 1); BOOST_CHECK_EQUAL(featureGraph.getNEdges(), 0); - // featureGraph.addFeature(ft2); - // BOOST_CHECK_EQUAL(featureGraph.getNVertices(), 2); - // BOOST_CHECK_EQUAL(featureGraph.getNEdges(), 1); + featureGraph.addFeature(ft2); + BOOST_CHECK_EQUAL(featureGraph.getNVertices(), 2); + BOOST_CHECK_EQUAL(featureGraph.getNEdges(), 1); }
--- a/include/Motion.hpp Mon Feb 20 19:32:27 2012 -0500 +++ b/include/Motion.hpp Fri Mar 02 19:32:54 2012 -0500 @@ -16,7 +16,7 @@ before saving. */ class FeatureTrajectory { public: - FeatureTrajectory(const int& frameNum, const cv::Point2f& p, const cv::Mat& homography); + FeatureTrajectory(const unsigned int& frameNum, const cv::Point2f& p, const cv::Mat& homography); FeatureTrajectory(TrajectoryPoint2fPtr& _positions, TrajectoryPoint2fPtr& _velocities); @@ -29,9 +29,6 @@ unsigned int getId(void) const { return positions->getId();} void setId(const unsigned int& id) { positions->setId(id);velocities->setId(id);} - void setLost(void) { lost = true;} - bool isLost(void) { return lost;} - unsigned int getFirstInstant(void) {return firstInstant;} unsigned int getLastInstant(void) {return lastInstant;} @@ -47,7 +44,7 @@ /// computes the distance according to the Beymer et al. algorithm bool minMaxSimilarity(const FeatureTrajectory& ft, const int& firstInstant, const int& lastInstant, const float& connectionDistance, const float& segmentationDistance); - void addPoint(const int& frameNum, const cv::Point2f& p, const cv::Mat& homography); + void addPoint(const unsigned int& frameNum, const cv::Point2f& p, const cv::Mat& homography); void shorten(void); @@ -60,7 +57,6 @@ friend std::stringstream& operator<<(std::stringstream& out, const FeatureTrajectory& ft); protected: - bool lost; /// \todo remove /// first frame number unsigned int firstInstant; /// last frame number