# HG changeset patch # User Nicolas Saunier # Date 1464728801 14400 # Node ID 2cade72d75ad95eda3d4de19113aca2621975120 # Parent 0662c87a61c931cf5bd893d98af07073482b7ee0 modified so there is no tracking outside of the mask (does not continue if features can still be matched) as requested diff -r 0662c87a61c9 -r 2cade72d75ad c/feature-based-tracking.cpp --- 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(static_cast(round(currPts[iter->pointNum].y)), static_cast(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 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(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