Mercurial Hosting > traffic-intelligence
changeset 122:654f1c748644
work on displaying matched features
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 15 Aug 2011 18:37:14 -0400 |
parents | c4d4b5b93add |
children | df3bdd8e50ba |
files | c/feature-based-tracking.cpp |
diffstat | 1 files changed, 46 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/c/feature-based-tracking.cpp Mon Aug 15 12:53:10 2011 -0400 +++ b/c/feature-based-tracking.cpp Mon Aug 15 18:37:14 2011 -0400 @@ -1,4 +1,5 @@ -#include "../include/Feature.hpp" +#include "Feature.hpp" +#include "utils.hpp" #include "opencv2/highgui/highgui.hpp" //#include "opencv2/imgproc/imgproc.hpp" @@ -20,16 +21,38 @@ BriefDescriptorExtractor brief(32); VideoCapture capture; - capture.open(atoi(argv[1])); + + Mat frame, display; + + 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 ) + { + capture.open(argv[1]); + if( capture.isOpened() ) + cout << "Video " << argv[1] << + ": width=" << capture.get(CV_CAP_PROP_FRAME_WIDTH) << + ", height=" << capture.get(CV_CAP_PROP_FRAME_HEIGHT) << + ", 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; + //cap.set(CV_CAP_PROP_POS_FRAMES, pos); + for (int i=0; i<pos; i++) + capture >> frame; + } + } + + // capture.open(atoi(argv[1])); if (!capture.isOpened()) { //help(argv); - cout << "capture device " << atoi(argv[1]) << " failed to open!" << endl; + cout << "capture device " << argv[1] << " failed to open!" << endl; return 1; } - Mat frame; - vector<DMatch> matches; BruteForceMatcher<Hamming> desc_matcher; @@ -44,9 +67,12 @@ const int DESIRED_FTRS = 500; GridAdaptedFeatureDetector detector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4); + int frameNum = 0; for (;;) { + frameNum+=2; capture >> frame; + cout << capture.get(CV_CAP_PROP_POS_FRAMES) << endl; if (frame.empty()) break; @@ -57,9 +83,21 @@ brief.compute(gray, query_kpts, query_desc); //Compute brief descriptors at each keypoint location // find how keypoints descriptions are matched to previous ones (in train kpts probably) - - imshow("frame", frame); - char key = (char)waitKey(2); + display = frame.clone(); + if (!train_kpts.empty()) + { + //vector<KeyPoint> test_kpts; + //warpKeypoints(H_prev.inv(), query_kpts, test_kpts); + //Mat mask = windowedMatchingMask(test_kpts, train_kpts, 25, 25); + desc_matcher.match(query_desc, train_desc, matches); + drawMatches(frame, train_kpts, frame, query_kpts, matches, display);//, Scalar::all(-1), Scalar::all(-1), vector<vector<char> >(), DrawMatchesFlags::DRAW_OVER_OUTIMG); + } // TODO do something like the match relative of the sample + + imshow("frame", display); + train_kpts = query_kpts; + int key = waitKey(0); + if (::interruptionKey(key)) + break; } Feature f;