Mercurial Hosting > traffic-intelligence
changeset 125:28907fde9855
work on klt tracker (problem on computer at poly)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 16 Aug 2011 19:35:07 -0400 |
parents | 1e68e18b1aa5 |
children | 336926453b28 |
files | c/feature-based-tracking.cpp |
diffstat | 1 files changed, 27 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- 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 <boost/shared_ptr.hpp> + #include <iostream> //#include <list> #include <vector> using namespace std; using namespace cv; - -//#include "cv.h" - -using namespace std; +using namespace boost; void drawMatchesRelative(const vector<KeyPoint>& train, const vector<KeyPoint>& query, std::vector<cv::DMatch>& matches, Mat& img) { for (int i = 0; i < (int)matches.size(); i++) @@ -33,19 +32,26 @@ } int main(int argc, char *argv[]) { - vector<TrajectoryPoint2f> features; + //vector<TrajectoryPoint2f> features; + BriefDescriptorExtractor brief(32); - + const int DESIRED_FTRS = 500; + //shared_ptr<FeatureDetector> detector = shared_ptr<FeatureDetector>(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<Hamming> descMatcher; + vector<DMatch> 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<DMatch> matches; - - BruteForceMatcher<Hamming> desc_matcher; - vector<KeyPoint> prevKpts, currKpts; - vector<unsigned char> 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<vector<char> >(), 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<vector<char> >(), 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;