changeset 800:2cade72d75ad dev

modified so there is no tracking outside of the mask (does not continue if features can still be matched) as requested
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 31 May 2016 17:06:41 -0400
parents 0662c87a61c9
children c5f98916297e d3e8dd9f3ca4
files c/feature-based-tracking.cpp
diffstat 1 files changed, 5 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/c/feature-based-tracking.cpp	Mon May 30 23:01:53 2016 -0400
+++ b/c/feature-based-tracking.cpp	Tue May 31 17:06:41 2016 -0400
@@ -62,10 +62,6 @@
 }
 
 void trackFeatures(const KLTFeatureTrackingParameters& params) {
-  // BriefDescriptorExtractor brief(32);
-  // const int DESIRED_FTRS = 500;
-  // GridAdaptedFeatureDetector detector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4);
-
   Mat homography = ::loadMat(params.homographyFilename, " ");
   Mat invHomography;
   if (params.display && !homography.empty())
@@ -174,8 +170,7 @@
 	break;
       }
     }
-
-      
+    
     cvtColor(frame, currentFrameBW, CV_RGB2GRAY);
     
     if (!prevPts.empty()) {
@@ -188,9 +183,9 @@
       while (iter != featurePointMatches.end()) {
 	bool deleteFeature = false;
 	  
-	if (status[iter->pointNum]) {
+	if (status[iter->pointNum] && (mask.at<uchar>(static_cast<int>(round(currPts[iter->pointNum].y)), static_cast<int>(round(currPts[iter->pointNum].x))) != 0)) {
 	  iter->feature->addPoint(frameNum, currPts[iter->pointNum], homography);
-
+	  
 	  deleteFeature = iter->feature->isDisplacementSmall(params.nDisplacements, minTotalFeatureDisplacement)
 	    || !iter->feature->isMotionSmooth(params.accelerationBound, params.deviationBound);
 	  if (deleteFeature)
@@ -219,14 +214,9 @@
       if (params.display) {
 	BOOST_FOREACH(FeaturePointMatch fp, featurePointMatches)
 	  fp.feature->draw(frame, invHomography, Colors::red());
-	// object detection
-	// vector<Rect> locations;
-	// hog.detectMultiScale(frame, locations, 0, Size(8,8), Size(32,32), 1.05, 2);
-	// BOOST_FOREACH(Rect r, locations)
-	//   rectangle(frame, r.tl(), r.br(), cv::Scalar(0,255,0), 3);
       }
     }
-      
+    
     // adding new features, using mask around existing feature positions
     Mat featureMask = mask.clone();
     for (unsigned int n=0;n<currPts.size(); n++)
@@ -234,7 +224,7 @@
 	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;
     goodFeaturesToTrack(currentFrameBW, newPts, params.maxNFeatures, params.featureQuality, params.minFeatureDistanceKLT, featureMask, params.blockSize, params.useHarrisDetector, params.k);
-    BOOST_FOREACH(Point2f p, newPts) { //for (unsigned int i=0; i<newPts.size(); i++) {
+    BOOST_FOREACH(Point2f p, newPts) {
       FeatureTrajectoryPtr f = FeatureTrajectoryPtr(new FeatureTrajectory(frameNum, p, homography));
       featurePointMatches.push_back(FeaturePointMatch(f, currPts.size()));
       currPts.push_back(p);