Mercurial Hosting > traffic-intelligence
diff c/feature-based-tracking.cpp @ 124:1e68e18b1aa5
renaming and working on klt
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 16 Aug 2011 12:31:22 -0400 |
parents | df3bdd8e50ba |
children | 28907fde9855 |
line wrap: on
line diff
--- 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<TrajectoryPoint2f> 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<pos; i++) + for (int i=0; i<params.frame1; i++) capture >> frame; } } @@ -70,19 +78,18 @@ BruteForceMatcher<Hamming> desc_matcher; - vector<Point2f> train_pts, query_pts; - vector<KeyPoint> train_kpts, query_kpts; + vector<KeyPoint> prevKpts, currKpts; vector<unsigned char> 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<vector<char> >(), DrawMatchesFlags::DRAW_OVER_OUTIMG); + 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); - 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; }