comparison 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
comparison
equal deleted inserted replaced
123:df3bdd8e50ba 124:1e68e18b1aa5
1 #include "Feature.hpp" 1 //#include "Feature.hpp"
2 #include "Parameters.hpp"
2 #include "utils.hpp" 3 #include "utils.hpp"
4
5 #include "src/Trajectory.h"
3 6
4 #include "opencv2/highgui/highgui.hpp" 7 #include "opencv2/highgui/highgui.hpp"
5 //#include "opencv2/imgproc/imgproc.hpp" 8 //#include "opencv2/imgproc/imgproc.hpp"
6 #include "opencv2/features2d/features2d.hpp" 9 #include "opencv2/features2d/features2d.hpp"
7 10
28 } 31 }
29 } 32 }
30 } 33 }
31 34
32 int main(int argc, char *argv[]) { 35 int main(int argc, char *argv[]) {
33 36 vector<TrajectoryPoint2f> features;
34 BriefDescriptorExtractor brief(32); 37 BriefDescriptorExtractor brief(32);
35 38
36 VideoCapture capture; 39 VideoCapture capture;
37 40
38 Mat frame, display; 41 Mat frame, display;
42 KLTFeatureTrackingParameters params;
43 params.frame1 = 0;
44 params.nFrames = -1;
45 // TODO ajouter klt paremeters, reprendre code de
46 // GoodFeaturesToTrackDetector feature_detector(Params.max_nfeatures, Params.feature_quality, Params.min_feature_distance_klt, Params.window_size, Params.useHarrisDetector_GoodFeaturesToTrackDetector, Params.k_GoodFeaturesToTrackDetector);
47 // search descriptor_match.h
39 48
40 if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0]))) // if no parameter or number parameter 49 if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0]))) // if no parameter or number parameter
41 capture.open(argc == 2 ? argv[1][0] - '0' : 0); 50 capture.open(argc == 2 ? argv[1][0] - '0' : 0);
42 else if( argc >= 2 ) 51 else if( argc >= 2 )
43 { 52 {
47 ": width=" << capture.get(CV_CAP_PROP_FRAME_WIDTH) << 56 ": width=" << capture.get(CV_CAP_PROP_FRAME_WIDTH) <<
48 ", height=" << capture.get(CV_CAP_PROP_FRAME_HEIGHT) << 57 ", height=" << capture.get(CV_CAP_PROP_FRAME_HEIGHT) <<
49 ", nframes=" << capture.get(CV_CAP_PROP_FRAME_COUNT) << endl; 58 ", nframes=" << capture.get(CV_CAP_PROP_FRAME_COUNT) << endl;
50 if( argc > 2 && isdigit(argv[2][0]) ) // could be used to reach first frame, dumping library messages to log file (2> /tmp/log.txt) 59 if( argc > 2 && isdigit(argv[2][0]) ) // could be used to reach first frame, dumping library messages to log file (2> /tmp/log.txt)
51 { 60 {
52 int pos; 61 sscanf(argv[2], "%d", &params.frame1);
53 sscanf(argv[2], "%d", &pos); 62 cout << "seeking to frame #" << params.frame1 << endl;
54 cout << "seeking to frame #" << pos << endl;
55 //cap.set(CV_CAP_PROP_POS_FRAMES, pos); 63 //cap.set(CV_CAP_PROP_POS_FRAMES, pos);
56 for (int i=0; i<pos; i++) 64 for (int i=0; i<params.frame1; i++)
57 capture >> frame; 65 capture >> frame;
58 } 66 }
59 } 67 }
60 68
61 // capture.open(atoi(argv[1])); 69 // capture.open(atoi(argv[1]));
68 76
69 vector<DMatch> matches; 77 vector<DMatch> matches;
70 78
71 BruteForceMatcher<Hamming> desc_matcher; 79 BruteForceMatcher<Hamming> desc_matcher;
72 80
73 vector<Point2f> train_pts, query_pts; 81 vector<KeyPoint> prevKpts, currKpts;
74 vector<KeyPoint> train_kpts, query_kpts;
75 vector<unsigned char> match_mask; 82 vector<unsigned char> match_mask;
76 83
77 Mat gray; 84 Mat gray;
78 85
79 Mat train_desc, query_desc; 86 Mat prevDesc, currDesc;
80 const int DESIRED_FTRS = 500; 87 const int DESIRED_FTRS = 500;
81 GridAdaptedFeatureDetector detector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4); 88 GridAdaptedFeatureDetector detector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4);
89
90 // TODO structure de donnee paires pointeur trajectory, numero de keypoint
82 91
83 int frameNum = 0; 92 for (int frameNum = 0; (params.frame1+frameNum < params.nFrames) || (params.nFrames < 0); frameNum++) {
84 for (;;)
85 {
86 frameNum++; 93 frameNum++;
87 //capture.set(CV_CAP_PROP_POS_FRAMES, frameNum); 94 //capture.set(CV_CAP_PROP_POS_FRAMES, frameNum);
88 //capture.grab();capture.grab();capture.retrieve(frame); 95 //capture.grab();capture.grab();capture.retrieve(frame);
89 capture >> frame; 96 capture >> frame;
90 //cout << capture.get(CV_CAP_PROP_POS_FRAMES) << endl; 97 //cout << capture.get(CV_CAP_PROP_POS_FRAMES) << endl;
91 while (frame.empty()) 98 while (frame.empty())
92 capture >> frame;//break; 99 capture >> frame;//break;
93 100
94 cvtColor(frame, gray, CV_RGB2GRAY); 101 cvtColor(frame, gray, CV_RGB2GRAY);
95 102
96 detector.detect(gray, query_kpts); //Find interest points 103 detector.detect(gray, currKpts);
97 cout << query_kpts.size() << " kpts" << endl; 104 //cout << currKpts.size() << " kpts" << endl;
98 105
99 brief.compute(gray, query_kpts, query_desc); //Compute brief descriptors at each keypoint location 106 brief.compute(gray, currKpts, currDesc); //Compute brief descriptors at each keypoint location
100 107
101 // find how keypoints descriptions are matched to previous ones (in train kpts probably)
102 //display = frame.clone(); 108 //display = frame.clone();
103 if (!train_kpts.empty()) 109 if (!prevKpts.empty())
104 { 110 {
105 desc_matcher.match(query_desc, train_desc, matches); 111 desc_matcher.match(currDesc, prevDesc, matches);
106 cout << "matches:" << matches.size() << endl; 112 cout << "matches:" << matches.size() << endl;
107 drawMatchesRelative(train_kpts, query_kpts, matches, frame); 113 drawMatchesRelative(prevKpts, currKpts, matches, frame);
108 //drawMatches(frame, train_kpts, frame, query_kpts, matches, display);//, Scalar::all(-1), Scalar::all(-1), vector<vector<char> >(), DrawMatchesFlags::DRAW_OVER_OUTIMG); 114 //drawMatches(frame, prevKpts, frame, currKpts, matches, display);//, Scalar::all(-1), Scalar::all(-1), vector<vector<char> >(), DrawMatchesFlags::DRAW_OVER_OUTIMG);
109 } 115 }
110 116
111 imshow("frame", frame); 117 imshow("frame", frame);
112 train_kpts = query_kpts; 118 prevKpts = currKpts;
113 query_desc.copyTo(train_desc); 119 currDesc.copyTo(prevDesc);
114 int key = waitKey(5); 120 int key = waitKey(0);
115 if (::interruptionKey(key)) 121 if (::interruptionKey(key))
116 break; 122 break;
117 } 123 }
118 124
119 Feature f;
120
121 return 0; 125 return 0;
122 } 126 }
123 127
124 128
125 /* ------------------ DOCUMENTATION ------------------ */ 129 /* ------------------ DOCUMENTATION ------------------ */