changeset 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 c06379f25ab8
children aa1061fb9695
files c/Motion.cpp c/feature-based-tracking.cpp include/Motion.hpp
diffstat 3 files changed, 33 insertions(+), 6 deletions(-) [+]
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]
+      }
     }
   }
 }
--- a/c/feature-based-tracking.cpp	Fri Nov 25 18:44:59 2011 -0500
+++ b/c/feature-based-tracking.cpp	Tue Nov 29 00:38:50 2011 -0500
@@ -270,7 +270,7 @@
   FeatureGraph featureGraph(params.mmConnectionDistance, params.mmSegmentationDistance, params.minFeatureTime);
 
   // main loop
-  // TODO version que l'on peut interrompre ?
+  // TODO version that can be interrupted?
   for (int frameNum = params.frame1; ((frameNum-params.frame1 < params.nFrames) || (params.nFrames < 0)); frameNum++) {
     vector<int> trajectoryIds;
     success  = trajectoryDB->trajectoryIdEndingAt(trajectoryIds, frameNum); // ending
--- a/include/Motion.hpp	Fri Nov 25 18:44:59 2011 -0500
+++ b/include/Motion.hpp	Tue Nov 29 00:38:50 2011 -0500
@@ -34,12 +34,18 @@
   unsigned int getFirstInstant(void) {return firstInstant;}
   unsigned int getLastInstant(void) {return lastInstant;}
 
+  //TrajectoryPoint2fPtr& getPositions(void) { return positions;}
+  //TrajectoryPoint2fPtr& getVelocities(void) { return velocities;}
+
   /// indicates whether the sum of the last nDisplacements displacements has been inferior to minFeatureDisplacement
   bool isDisplacementSmall(const unsigned int& nDisplacements, const float& minTotalFeatureDisplacement) const;
 
   /// indicates whether the last two displacements are smooth (limited acceleration and angle)
   bool isMotionSmooth(const int& accelerationBound, const int& deviationBound) const;
 
+  /// computes the distance according to the Beymer et al. algorithm
+  bool minMaxSimilarity(const FeatureTrajectory& ft, const int& firstInstant, const int& lastInstant, float connectionDistance, float segmentationDistance);
+
   void addPoint(const int& frameNum, const cv::Point2f& p, const cv::Mat& homography);
 
   void shorten(void);