Reputation: 267
I already calculate the descriptors, but now, I would like to clean the outliers, before of transforming it from keypoint to float.
I know that this can be done automatically by
BruteForceMatcher<cv::L2<float> > matcher;
std::vector<cv::DMatch> matches;
matcher.match(descriptors1,descriptors2, matches);
std::nth_element(matches.begin(),matches.begin()+24, matches.end());
matches.erase(matches.begin()+25, matches.end());`
But this is only useful if the next step is drawing the matches, and actually what I would like to do is obtain the best 25 matches for posprocessing in some image registration stuff.
Any help would be useful. Thanks
Iván
Upvotes: 1
Views: 2227
Reputation: 21
Use the trainIdx and queryIdx attributes of each element in the Dmatch vector to extract corresponding indexes of matching from the vector of keypoints you provided.
Basically, matches.at(i).trainIdx and matches.at(i).queryIdx will give you the indices of the 'i'th corresponding match. The best part is, the matches are arranged in descending order of quality, as in, i=1 will be a better match than i=3, and so on. So, in your code, you are extracting the best 24 matches.
I don't know if you still need help with this question, it's been a year since you asked it. But I had the same question and I chanced upon your question. It took me time to figure out as well. I thought it was my duty to answer this question lest someone else also chance upon the same question and needs help. Let there be light!
Upvotes: 1