Mercurial > hg > nsaunier > traffic-intelligence
comparison c/Motion.cpp @ 186:6c48283a78ca
work on feature similarity, issue with getting point
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Tue, 29 Nov 2011 00:38:50 -0500 |
| parents | 3a4eef37384f |
| children | aa1061fb9695 |
comparison
equal
deleted
inserted
replaced
| 185:c06379f25ab8 | 186:6c48283a78ca |
|---|---|
| 60 float cosine = scalarProduct((*velocities)[nPositions-3],(*velocities)[nPositions-2]) / (displacementDistances[nPositions-3] * displacementDistances[nPositions-2]); | 60 float cosine = scalarProduct((*velocities)[nPositions-3],(*velocities)[nPositions-2]) / (displacementDistances[nPositions-3] * displacementDistances[nPositions-2]); |
| 61 | 61 |
| 62 result &= (ratio < accelerationBound) & (cosine > deviationBound); | 62 result &= (ratio < accelerationBound) & (cosine > deviationBound); |
| 63 } | 63 } |
| 64 return result; | 64 return result; |
| 65 } | |
| 66 | |
| 67 bool FeatureTrajectory::minMaxSimilarity(const FeatureTrajectory& ft, const int& firstInstant, const int& lastInstant, float connectionDistance, float segmentationDistance) { | |
| 68 Point2f diff = positions->getPointAtInstant(firstInstant)-ft.positions->getPointAtInstant(firstInstant); | |
| 69 float minDistance = norm(diff); | |
| 70 float maxDistance = minDistance; | |
| 71 bool connected = minDistance <= connectionDistance; | |
| 72 int t=firstInstant+1; | |
| 73 while (t <= lastInstant && connected) { | |
| 74 diff = positions->getPointAtInstant(t)-ft.positions->getPointAtInstant(t); | |
| 75 float distance = norm(diff); | |
| 76 if (distance < minDistance) | |
| 77 minDistance = distance; | |
| 78 else if (distance > maxDistance) | |
| 79 maxDistance = distance; | |
| 80 connected = connected && (maxDistance-minDistance < segmentationDistance); | |
| 81 t++; | |
| 82 } | |
| 83 | |
| 84 return connected; | |
| 65 } | 85 } |
| 66 | 86 |
| 67 void FeatureTrajectory::addPoint(const int& frameNum, const Point2f& p, const Mat& homography) { | 87 void FeatureTrajectory::addPoint(const int& frameNum, const Point2f& p, const Mat& homography) { |
| 68 Point2f pp = p; | 88 Point2f pp = p; |
| 69 if (!homography.empty()) | 89 if (!homography.empty()) |
| 127 vi!=vertices(graph).second; ++vi) { // vi pointer to vertex_descriptor | 147 vi!=vertices(graph).second; ++vi) { // vi pointer to vertex_descriptor |
| 128 FeatureTrajectoryPtr ft2 = graph[*vi].feature; | 148 FeatureTrajectoryPtr ft2 = graph[*vi].feature; |
| 129 unsigned int lastInstant = min(ft->getLastInstant(), ft2->getLastInstant()); | 149 unsigned int lastInstant = min(ft->getLastInstant(), ft2->getLastInstant()); |
| 130 unsigned int firstInstant = max(ft->getLastInstant(), ft2->getLastInstant()); | 150 unsigned int firstInstant = max(ft->getLastInstant(), ft2->getLastInstant()); |
| 131 if (lastInstant-firstInstant > minFeatureTime) { // equivalent to lastInstant-firstInstant+1 >= minFeatureTime | 151 if (lastInstant-firstInstant > minFeatureTime) { // equivalent to lastInstant-firstInstant+1 >= minFeatureTime |
| 132 // compute the distance and add edge if ok | 152 if (ft->minMaxSimilarity(*ft2, firstInstant, lastInstant, connectionDistance, segmentationDistance)) { |
| 133 UndirectedGraph::edge_descriptor e; | 153 UndirectedGraph::edge_descriptor e; |
| 134 bool unused; | 154 bool unused; |
| 135 tie(e, unused) = add_edge(newVertex, *vi, graph); | 155 tie(e, unused) = add_edge(newVertex, *vi, graph); |
| 136 // no need to add measures to graph[e] | 156 // no need to add measures to graph[e] |
| 157 } | |
| 137 } | 158 } |
| 138 } | 159 } |
| 139 } | 160 } |
| 140 | 161 |
| 141 string FeatureGraph::informationString(void) { | 162 string FeatureGraph::informationString(void) { |
