# HG changeset patch # User Nicolas Saunier # Date 1313537707 14400 # Node ID 28907fde9855f3c6bf12a2e3dd82135f0f667fc7 # Parent 1e68e18b1aa5f6a850d2e69875fa1aaff2909e7d work on klt tracker (problem on computer at poly) diff -r 1e68e18b1aa5 -r 28907fde9855 c/feature-based-tracking.cpp --- a/c/feature-based-tracking.cpp Tue Aug 16 12:31:22 2011 -0400 +++ b/c/feature-based-tracking.cpp Tue Aug 16 19:35:07 2011 -0400 @@ -8,16 +8,15 @@ //#include "opencv2/imgproc/imgproc.hpp" #include "opencv2/features2d/features2d.hpp" +#include + #include //#include #include using namespace std; using namespace cv; - -//#include "cv.h" - -using namespace std; +using namespace boost; void drawMatchesRelative(const vector& train, const vector& query, std::vector& matches, Mat& img) { for (int i = 0; i < (int)matches.size(); i++) @@ -33,19 +32,26 @@ } int main(int argc, char *argv[]) { - vector features; + //vector features; + BriefDescriptorExtractor brief(32); - + const int DESIRED_FTRS = 500; + //shared_ptr detector = shared_ptr(new GridAdaptedFeatureDetector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4)); + GridAdaptedFeatureDetector detector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4); + VideoCapture capture; + Mat frame, display; - 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); + // TODO ajouter klt paremeters, reprendre code de opencvfeaturetracker + //GoodFeaturesToTrackDetector 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 + BruteForceMatcher descMatcher; + vector matches; + 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); else if( argc >= 2 ) @@ -74,27 +80,16 @@ return 1; } - vector matches; - - BruteForceMatcher desc_matcher; - vector prevKpts, currKpts; - vector match_mask; Mat gray; 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 - - 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); + int key = '?'; + for (int frameNum = 0; ((params.frame1+frameNum < params.nFrames) || (params.nFrames < 0)) && !::interruptionKey(key); frameNum++) { capture >> frame; - //cout << capture.get(CV_CAP_PROP_POS_FRAMES) << endl; + cout << capture.get(CV_CAP_PROP_POS_FRAMES) << endl; while (frame.empty()) capture >> frame;//break; @@ -106,20 +101,18 @@ brief.compute(gray, currKpts, currDesc); //Compute brief descriptors at each keypoint location //display = frame.clone(); - if (!prevKpts.empty()) - { - desc_matcher.match(currDesc, prevDesc, matches); - cout << "matches:" << matches.size() << endl; - drawMatchesRelative(prevKpts, currKpts, matches, frame); - //drawMatches(frame, prevKpts, frame, currKpts, matches, display);//, Scalar::all(-1), Scalar::all(-1), vector >(), DrawMatchesFlags::DRAW_OVER_OUTIMG); - } - + if (!prevKpts.empty()) { + cout << matches.size() << " matches" << endl; + descMatcher.match(currDesc, prevDesc, matches); + cout << matches.size() << " matches" << endl; + 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); prevKpts = currKpts; currDesc.copyTo(prevDesc); - int key = waitKey(0); - if (::interruptionKey(key)) - break; + key = waitKey(0); } return 0;