Mercurial > hg > nsaunier > traffic-intelligence
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 199:ca9d9104afba | 200:0a27fa343257 |
|---|---|
| 18 using namespace cv; | 18 using namespace cv; |
| 19 using namespace boost; | 19 using namespace boost; |
| 20 | 20 |
| 21 /******************** FeatureTrajectory ********************/ | 21 /******************** FeatureTrajectory ********************/ |
| 22 | 22 |
| 23 FeatureTrajectory::FeatureTrajectory(const int& frameNum, const cv::Point2f& p, const Mat& homography) | 23 FeatureTrajectory::FeatureTrajectory(const unsigned int& frameNum, const cv::Point2f& p, const Mat& homography) |
| 24 : lost(false) { | 24 : firstInstant(frameNum), lastInstant(frameNum) { |
| 25 positions = TrajectoryPoint2fPtr(new TrajectoryPoint2f()); | 25 positions = TrajectoryPoint2fPtr(new TrajectoryPoint2f()); |
| 26 velocities = TrajectoryPoint2fPtr(new TrajectoryPoint2f()); | 26 velocities = TrajectoryPoint2fPtr(new TrajectoryPoint2f()); |
| 27 addPoint(frameNum, p, homography); | 27 addPoint(frameNum, p, homography); |
| 28 } | 28 } |
| 29 | 29 |
| 30 FeatureTrajectory::FeatureTrajectory(TrajectoryPoint2fPtr& _positions, TrajectoryPoint2fPtr& _velocities) | 30 FeatureTrajectory::FeatureTrajectory(TrajectoryPoint2fPtr& _positions, TrajectoryPoint2fPtr& _velocities) { |
| 31 : lost(false) { | |
| 32 positions = _positions; | 31 positions = _positions; |
| 33 velocities = _velocities; | 32 velocities = _velocities; |
| 33 positions->computeInstants(firstInstant, lastInstant); | |
| 34 } | 34 } |
| 35 | 35 |
| 36 FeatureTrajectory::FeatureTrajectory(const int& id, TrajectoryDBAccessList<Point2f>& trajectoryDB, const string& positionsTableName, const string& velocitiesTableName) { | 36 FeatureTrajectory::FeatureTrajectory(const int& id, TrajectoryDBAccessList<Point2f>& trajectoryDB, const string& positionsTableName, const string& velocitiesTableName) { |
| 37 bool success = trajectoryDB.read(positions, id, positionsTableName); | 37 bool success = trajectoryDB.read(positions, id, positionsTableName); |
| 38 if (!success) | 38 if (!success) |
| 89 } | 89 } |
| 90 | 90 |
| 91 return connected; | 91 return connected; |
| 92 } | 92 } |
| 93 | 93 |
| 94 void FeatureTrajectory::addPoint(const int& frameNum, const Point2f& p, const Mat& homography) { | 94 void FeatureTrajectory::addPoint(const unsigned int& frameNum, const Point2f& p, const Mat& homography) { |
| 95 Point2f pp = p; | 95 Point2f pp = p; |
| 96 if (!homography.empty()) | 96 if (!homography.empty()) |
| 97 pp = project(p, homography); | 97 pp = project(p, homography); |
| 98 positions->add(frameNum, pp); | 98 positions->add(frameNum, pp); |
| 99 if (frameNum < firstInstant) | |
| 100 firstInstant = frameNum; | |
| 101 if (frameNum > lastInstant) | |
| 102 lastInstant = frameNum; | |
| 99 computeMotionData(frameNum); | 103 computeMotionData(frameNum); |
| 100 assert(positions.size() == displacementDistances.size()+1); | 104 assert(positions.size() == displacementDistances.size()+1); |
| 101 assert(positions.size() == velocities.size()+1); | 105 assert(positions.size() == velocities.size()+1); |
| 102 } | 106 } |
| 103 | 107 |
| 151 vertex_descriptor newVertex = add_vertex(graph); | 155 vertex_descriptor newVertex = add_vertex(graph); |
| 152 graph[newVertex].feature = ft; | 156 graph[newVertex].feature = ft; |
| 153 for (graph_traits<UndirectedGraph>::vertex_iterator vi = vertices(graph).first; | 157 for (graph_traits<UndirectedGraph>::vertex_iterator vi = vertices(graph).first; |
| 154 vi!=vertices(graph).second; ++vi) { // vi pointer to vertex_descriptor | 158 vi!=vertices(graph).second; ++vi) { // vi pointer to vertex_descriptor |
| 155 FeatureTrajectoryPtr ft2 = graph[*vi].feature; | 159 FeatureTrajectoryPtr ft2 = graph[*vi].feature; |
| 156 int lastInstant = static_cast<int>(min(ft->getLastInstant(), ft2->getLastInstant())); | 160 if (newVertex != *vi) { |
| 157 int firstInstant = static_cast<int>(max(ft->getFirstInstant(), ft2->getFirstInstant())); | 161 int lastInstant = static_cast<int>(min(ft->getLastInstant(), ft2->getLastInstant())); |
| 158 if (lastInstant-firstInstant > static_cast<int>(minFeatureTime)) { // equivalent to lastInstant-firstInstant+1 >= minFeatureTime | 162 int firstInstant = static_cast<int>(max(ft->getFirstInstant(), ft2->getFirstInstant())); |
| 159 if (ft->minMaxSimilarity(*ft2, firstInstant, lastInstant, connectionDistance, segmentationDistance)) { | 163 if (lastInstant-firstInstant > static_cast<int>(minFeatureTime)) { // equivalent to lastInstant-firstInstant+1 >= minFeatureTime |
| 160 UndirectedGraph::edge_descriptor e; | 164 if (ft->minMaxSimilarity(*ft2, firstInstant, lastInstant, connectionDistance, segmentationDistance)) { |
| 161 bool unused; | 165 UndirectedGraph::edge_descriptor e; |
| 162 tie(e, unused) = add_edge(newVertex, *vi, graph); | 166 bool unused; |
| 163 // no need to add measures to graph[e] (edge properties) | 167 tie(e, unused) = add_edge(newVertex, *vi, graph); |
| 168 // no need to add measures to graph[e] (edge properties) | |
| 169 } | |
| 164 } | 170 } |
| 165 } | 171 } |
| 166 } | 172 } |
| 167 } | 173 } |
| 168 | 174 |
