Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opencv - Getting Pixel Coordinates from Feature Matching

Can anyone help me? I want to get the x and y coordinates of the best pixels the feature matcher selects in the code provided, using c++ with opencv.

http://opencv.itseez.com/doc/tutorials/features2d/feature_flann_matcher/feature_flann_matcher.html#feature-flann-matcher

Been looking around, but can't get anything to work.

Any help is greatly appreciated!

like image 693
user1088410 Avatar asked Dec 08 '11 19:12

user1088410


1 Answers

The DMatch class gives you the distance between the two matching KeyPoints (train and query). So, the best pairs detected should have the smallest distance. The tutorial grabs all matches that are less than 2*(minimum pair distance) and considers those the best.

So, to get the (x, y) coordinates of the best matches. You should use the good_matches (which is a list of DMatch objects) to look up the corresponding indices from the two different KeyPoint vectors (keypoints_1 and keypoints_2). Something like:

for(size_t i = 0; i < good_matches.size(); i++)
{
    Point2f point1 = keypoints_1[good_matches[i].queryIdx].pt;
    Point2f point2 = keypoints_2[good_matches[i].trainIdx].pt;
    // do something with the best points...
}
like image 110
mevatron Avatar answered Oct 16 '22 05:10

mevatron