changeset 130:2a6e7a9a5c53

changed to goodFeaturesToTrack instead of generic detectors
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 17 Aug 2011 17:30:30 -0400
parents 4742b2b6d851
children 3a11dba30655
files c/feature-based-tracking.cpp
diffstat 1 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/c/feature-based-tracking.cpp	Wed Aug 17 17:14:00 2011 -0400
+++ b/c/feature-based-tracking.cpp	Wed Aug 17 17:30:30 2011 -0400
@@ -1,4 +1,4 @@
-//#include "Feature.hpp"
+#include "Feature.hpp"
 #include "Parameters.hpp"
 #include "cvutils.hpp"
 #include "utils.hpp"
@@ -43,8 +43,6 @@
 }
 
 int main(int argc, char *argv[]) {
-  //vector<TrajectoryPoint2f> features;
-  
   BriefDescriptorExtractor brief(32);
   const int DESIRED_FTRS = 500;
   //shared_ptr<FeatureDetector> detector = shared_ptr<FeatureDetector>(new GridAdaptedFeatureDetector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4));
@@ -62,7 +60,7 @@
   params.windowSize = 3; 
   params.useHarrisDetector = false;
   params.k = 0.4;
-  GoodFeaturesToTrackDetector detector(params.maxNFeatures, params.featureQuality, params.minFeatureDistanceKLT, params.windowSize, params.useHarrisDetector, params.k);
+  //GoodFeaturesToTrackDetector detector(params.maxNFeatures, params.featureQuality, params.minFeatureDistanceKLT, params.windowSize, params.useHarrisDetector, params.k);
 
   params.pyramidLevel = 3;
   params.maxNumberTrackingIterations = 20; // 30
@@ -104,12 +102,13 @@
     }
   
   vector<KeyPoint> prevKpts, currKpts;
-  vector<Point2f> prevPts, currPts;
+  vector<Point2f> prevPts, currPts, newPts;
   vector<uchar> status;
   vector<float> errors;
   Mat prevDesc, currDesc;
 
-  
+  vector<FeatureTrajectory> features;
+    
   // TODO structure de donnee paires pointeur trajectory, numero de keypoint
   int key = '?'; 
   for (int frameNum = params.frame1; ((params.frame1+frameNum < params.nFrames) || (params.nFrames < 0)) && !::interruptionKey(key); frameNum++) {
@@ -119,6 +118,9 @@
 	capture >> frame;//break;
       
       cvtColor(frame, currentFrameBW, CV_RGB2GRAY);
+
+      // "normal" feature detectors: detect features here
+      // detector.detect(currentFrameBW, currKpts); // see video_homography c++ sample
       
       if (!prevPts.empty()) {
 	//::keyPoints2Points(prevKpts, prevPts);
@@ -145,8 +147,9 @@
 	for (int j=MAX(0, currPts[n].x-params.minFeatureDistanceKLT); j<MIN(videoSize.width, currPts[n].x+params.minFeatureDistanceKLT+1); j++)
 	  for (int i=MAX(0, currPts[n].y-params.minFeatureDistanceKLT); i<MIN(videoSize.height, currPts[n].y+params.minFeatureDistanceKLT+1); i++)
 	    featureMask.at<uchar>(i,j)=0;
-      detector.detect(currentFrameBW, currKpts, featureMask);
-      ::keyPoints2Points(currKpts, currPts, false);
+      goodFeaturesToTrack(currentFrameBW, newPts, params.maxNFeatures, params.featureQuality, params.minFeatureDistanceKLT, featureMask, params.windowSize, params.useHarrisDetector, params.k);
+      currPts.insert(currPts.end(), newPts.begin(), newPts.end());
+      //::keyPoints2Points(currKpts, currPts, false);
 
       //brief.compute(currentFrameBW, currKpts, currDesc); //Compute brief descriptors at each keypoint location