1

is there a way to set a threshold for potential matched pairs of image descriptors calculated by DescriptorMatcher in OpenCV's features2d?

In detail, I have a Bruteforce-Matcher with which I want to calculate descriptor pairs of two images and only pairs with a minimum distance of threshold should go in matches.

BFMatcher matcher(NORM_L2, true);
vector<DMatch> matches;
matcher.match(descriptors1, descriptors2, matches);

Thank's for your help!

Hans Sperker
  • 1,347
  • 2
  • 15
  • 37

2 Answers2

3

Ok, so I did some more reading and found some interesting Posts like How to use flann based matcher, or generally flann in opencv? and figured out my own way ;-)

First I used FlannBasedMatcher to match the calculated descriptors. After that I sorted the matches (they get sorted by distance in ascending order by default). Created a second DMatch vector and just added the matches which had a distance below a distance-threshold chosen by me. Thats it. This way I can also choose the top N matches it the threshold is selected to bad.

May not be the best / cleanest way but it's a quick solution which is ok for the prototypal situation.

Community
  • 1
  • 1
Hans Sperker
  • 1,347
  • 2
  • 15
  • 37
1

Use radiusMatch instead of match

matcher.radiusMatch(descriptors1, descriptors2, matches, your-threshold);
  • Wrong. The documentation says: "For each query descriptor, finds the training descriptors not farther than the specified distance.", while the OP is asking *only pairs with a minimum distance of threshold*. – aledalgrande Jul 22 '14 at 00:41
  • i ran the code. please don't base your answers only on documentation. –  Jul 22 '14 at 10:58
  • It clearly says *maxDistance* in the source code: https://github.com/Itseez/opencv/blob/a26bed16e64401d790930dc73dd29462bddd8d2c/modules/features2d/src/matchers.cpp#L1139 – aledalgrande Jul 22 '14 at 18:46
  • what is the difference exactly between "descriptors not farther than the specified distance" and "pairs with a minimum distance of threshold"? –  Jul 23 '14 at 13:28
  • They are exactly the opposite, @Moe! – aledalgrande Jul 23 '14 at 19:47
  • 1
    While I agree with @aledalgrande, it seems that this solution will beat the purpose of the matching, so I think jstr actually meant maximum, in which case the solution of Moe should work. – Leon van Noord Sep 30 '14 at 12:13