# HG changeset patch # User Nicolas Saunier # Date 1313512282 14400 # Node ID 1e68e18b1aa5f6a850d2e69875fa1aaff2909e7d # Parent df3bdd8e50ba1f8a4c4038ffae3acde54a88f353 renaming and working on klt diff -r df3bdd8e50ba -r 1e68e18b1aa5 c/feature-based-tracking.cpp --- a/c/feature-based-tracking.cpp Tue Aug 16 00:46:22 2011 -0400 +++ b/c/feature-based-tracking.cpp Tue Aug 16 12:31:22 2011 -0400 @@ -1,6 +1,9 @@ -#include "Feature.hpp" +//#include "Feature.hpp" +#include "Parameters.hpp" #include "utils.hpp" +#include "src/Trajectory.h" + #include "opencv2/highgui/highgui.hpp" //#include "opencv2/imgproc/imgproc.hpp" #include "opencv2/features2d/features2d.hpp" @@ -30,12 +33,18 @@ } int main(int argc, char *argv[]) { - + vector features; BriefDescriptorExtractor brief(32); VideoCapture capture; Mat frame, display; + KLTFeatureTrackingParameters params; + params.frame1 = 0; + params.nFrames = -1; + // TODO ajouter klt paremeters, reprendre code de + // GoodFeaturesToTrackDetector feature_detector(Params.max_nfeatures, Params.feature_quality, Params.min_feature_distance_klt, Params.window_size, Params.useHarrisDetector_GoodFeaturesToTrackDetector, Params.k_GoodFeaturesToTrackDetector); + // search descriptor_match.h if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0]))) // if no parameter or number parameter capture.open(argc == 2 ? argv[1][0] - '0' : 0); @@ -49,11 +58,10 @@ ", nframes=" << capture.get(CV_CAP_PROP_FRAME_COUNT) << endl; if( argc > 2 && isdigit(argv[2][0]) ) // could be used to reach first frame, dumping library messages to log file (2> /tmp/log.txt) { - int pos; - sscanf(argv[2], "%d", &pos); - cout << "seeking to frame #" << pos << endl; + sscanf(argv[2], "%d", ¶ms.frame1); + cout << "seeking to frame #" << params.frame1 << endl; //cap.set(CV_CAP_PROP_POS_FRAMES, pos); - for (int i=0; i> frame; } } @@ -70,19 +78,18 @@ BruteForceMatcher desc_matcher; - vector train_pts, query_pts; - vector train_kpts, query_kpts; + vector prevKpts, currKpts; vector match_mask; Mat gray; - Mat train_desc, query_desc; + Mat prevDesc, currDesc; const int DESIRED_FTRS = 500; GridAdaptedFeatureDetector detector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4); + + // TODO structure de donnee paires pointeur trajectory, numero de keypoint - int frameNum = 0; - for (;;) - { + for (int frameNum = 0; (params.frame1+frameNum < params.nFrames) || (params.nFrames < 0); frameNum++) { frameNum++; //capture.set(CV_CAP_PROP_POS_FRAMES, frameNum); //capture.grab();capture.grab();capture.retrieve(frame); @@ -93,31 +100,28 @@ cvtColor(frame, gray, CV_RGB2GRAY); - detector.detect(gray, query_kpts); //Find interest points - cout << query_kpts.size() << " kpts" << endl; + detector.detect(gray, currKpts); + //cout << currKpts.size() << " kpts" << endl; - brief.compute(gray, query_kpts, query_desc); //Compute brief descriptors at each keypoint location + brief.compute(gray, currKpts, currDesc); //Compute brief descriptors at each keypoint location - // find how keypoints descriptions are matched to previous ones (in train kpts probably) //display = frame.clone(); - if (!train_kpts.empty()) + if (!prevKpts.empty()) { - desc_matcher.match(query_desc, train_desc, matches); + desc_matcher.match(currDesc, prevDesc, matches); cout << "matches:" << matches.size() << endl; - drawMatchesRelative(train_kpts, query_kpts, matches, frame); - //drawMatches(frame, train_kpts, frame, query_kpts, matches, display);//, Scalar::all(-1), Scalar::all(-1), vector >(), DrawMatchesFlags::DRAW_OVER_OUTIMG); + drawMatchesRelative(prevKpts, currKpts, matches, frame); + //drawMatches(frame, prevKpts, frame, currKpts, matches, display);//, Scalar::all(-1), Scalar::all(-1), vector >(), DrawMatchesFlags::DRAW_OVER_OUTIMG); } imshow("frame", frame); - train_kpts = query_kpts; - query_desc.copyTo(train_desc); - int key = waitKey(5); + prevKpts = currKpts; + currDesc.copyTo(prevDesc); + int key = waitKey(0); if (::interruptionKey(key)) break; } - Feature f; - return 0; } diff -r df3bdd8e50ba -r 1e68e18b1aa5 include/Parameters.hpp --- a/include/Parameters.hpp Tue Aug 16 00:46:22 2011 -0400 +++ b/include/Parameters.hpp Tue Aug 16 12:31:22 2011 -0400 @@ -3,7 +3,9 @@ /// \todo Class for parameters, with utilities to save and load from configuration files -struct FeatureTrackingParameters { +#include + +struct KLTFeatureTrackingParameters { /// whether to load saved features, or compute them bool loadFeatures; @@ -32,6 +34,11 @@ float maxDistance; float minVelocityCosine; int minNFeaturesPerGroup; + + //KLTFeatureTrackingParameters(const int argc, char* argv[]); + + //KLTFeatureTrackingParameters(bool loadFeatures, std::string videoFilename, int videoFPS, int measurementPrecision, int frame1, int nFrames, int maxNFeatures, float featureQuality, float minFeatureDistanceKLT, int windowSize, int pyramidLevel, int nFramesDisplacement, float minFeatureDisplacement, float accelerationBound, float deviationBound, int nFramesSmoothing, int nFramesVelocity, int maxNumberTrackingIterations, float minTrackingError, int minFeatureTime, float mmConnectionDistance, float mmSegmentationDistance, float maxDistance, float minVelocityCosine, int minNFeaturesPerGroup); + }; #endif