diff 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
line wrap: on
line diff
--- a/c/Motion.cpp	Fri Nov 25 18:44:59 2011 -0500
+++ b/c/Motion.cpp	Tue Nov 29 00:38:50 2011 -0500
@@ -64,6 +64,26 @@
   return result;
 }
 
+bool FeatureTrajectory::minMaxSimilarity(const FeatureTrajectory& ft, const int& firstInstant, const int& lastInstant, float connectionDistance, float segmentationDistance) {
+  Point2f diff = positions->getPointAtInstant(firstInstant)-ft.positions->getPointAtInstant(firstInstant);
+  float minDistance = norm(diff);
+  float maxDistance = minDistance;
+  bool connected = minDistance <= connectionDistance;
+  int t=firstInstant+1;
+  while (t <= lastInstant && connected) {
+    diff = positions->getPointAtInstant(t)-ft.positions->getPointAtInstant(t);
+    float distance = norm(diff);
+    if (distance < minDistance)
+      minDistance = distance;
+    else if (distance > maxDistance)
+      maxDistance = distance;
+    connected = connected && (maxDistance-minDistance < segmentationDistance);
+    t++;
+  }
+
+  return connected;
+}
+
 void FeatureTrajectory::addPoint(const int& frameNum, const Point2f& p, const Mat& homography) {
   Point2f pp = p;
   if (!homography.empty())
@@ -129,11 +149,12 @@
     unsigned int lastInstant = min(ft->getLastInstant(), ft2->getLastInstant());
     unsigned int firstInstant = max(ft->getLastInstant(), ft2->getLastInstant());
     if (lastInstant-firstInstant > minFeatureTime) { // equivalent to lastInstant-firstInstant+1 >= minFeatureTime
-      // compute the distance and add edge if ok
-      UndirectedGraph::edge_descriptor e;
-      bool unused;
-      tie(e, unused) = add_edge(newVertex, *vi, graph);
-      // no need to add measures to graph[e]
+      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]
+      }
     }
   }
 }