Mercurial Hosting > traffic-intelligence
diff c/Motion.cpp @ 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 | aeab0b88c9b6 |
children | f7ddfc4aeb1e |
line wrap: on
line diff
--- 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) + } } } }