# HG changeset patch # User Nicolas Saunier # Date 1313469982 14400 # Node ID df3bdd8e50ba1f8a4c4038ffae3acde54a88f353 # Parent 654f1c748644a36e2c861bbd61d7da19a5c7682f displays tracking from video and webcam diff -r 654f1c748644 -r df3bdd8e50ba c/feature-based-tracking.cpp --- a/c/feature-based-tracking.cpp Mon Aug 15 18:37:14 2011 -0400 +++ b/c/feature-based-tracking.cpp Tue Aug 16 00:46:22 2011 -0400 @@ -16,6 +16,19 @@ using namespace std; +void drawMatchesRelative(const vector& train, const vector& query, std::vector& matches, Mat& img) { + for (int i = 0; i < (int)matches.size(); i++) + { + Point2f pt_new = query[matches[i].queryIdx].pt; + Point2f pt_old = train[matches[i].trainIdx].pt; + Point2f dist = pt_new - pt_old; + if (norm(dist) < 20) { + cv::line(img, pt_new, pt_old, Scalar(125, 255, 125), 1); + cv::circle(img, pt_new, 2, Scalar(255, 0, 125), 1); + } + } +} + int main(int argc, char *argv[]) { BriefDescriptorExtractor brief(32); @@ -70,32 +83,35 @@ int frameNum = 0; for (;;) { - frameNum+=2; + frameNum++; + //capture.set(CV_CAP_PROP_POS_FRAMES, frameNum); + //capture.grab();capture.grab();capture.retrieve(frame); capture >> frame; - cout << capture.get(CV_CAP_PROP_POS_FRAMES) << endl; - if (frame.empty()) - break; + //cout << capture.get(CV_CAP_PROP_POS_FRAMES) << endl; + while (frame.empty()) + capture >> frame;//break; cvtColor(frame, gray, CV_RGB2GRAY); detector.detect(gray, query_kpts); //Find interest points + cout << query_kpts.size() << " kpts" << endl; 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) - display = frame.clone(); + //display = frame.clone(); if (!train_kpts.empty()) { - //vector 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 >(), DrawMatchesFlags::DRAW_OVER_OUTIMG); - } // TODO do something like the match relative of the sample + 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 >(), DrawMatchesFlags::DRAW_OVER_OUTIMG); + } - imshow("frame", display); + imshow("frame", frame); train_kpts = query_kpts; - int key = waitKey(0); + query_desc.copyTo(train_desc); + int key = waitKey(5); if (::interruptionKey(key)) break; }