match() & knnMatch duplicates results

asked 2013-06-18 04:43:29 -0600

ShadowTS gravatar image

updated 2013-06-18 04:46:16 -0600

Hello, I have a problem in my Andorid (NDK) implementation of Feature Detector + Descriptor + Matcher.

I'm using knnMatch with k = 2 to match descriptors extracted from camera frame to descriptor extracted from a fixed image.

Then I filter outliers with ratio test, checking the ratio between the first match "distance" property and the second match "distance" property, for each.

If the ratio is smaller then a threshold then i save the first match in a new vector containing only "good matches". I also save trainIdx and queryIdx corresponding to each "good match" in 2 vecors.

So now I expect that one between trainIdx vector and queryIdx vector does not contain duplicates. I think this because I expect that knnMatch() and match() functions cicle through all the descriptors of train (OR query) descriptor-vectors and find the best (or best 2) matches in the other descriptor-vector. In this way there could be duplicates between query indexes, because 2 train descriptors CAN match the same query descriptor, but there should not be duplicates in the train indexes! Even if the match are computed in the opposite way (functions cicle through all the descriptors of query descriptor-vectors and find the best (or best 2) matches in the train descriptor-vector), one of the two indexes vectors must not have duplicates.

So I'm doing something wrong, or the matching functions work in a different way from what I think?

Notes: I'm using ORB keypoint detector and descriptor extractor, and BFMatcher.

edit retag flag offensive close merge delete


Is the crossCheck of your BFMatcher enabled? Or did I completely misunderstand you.

KarlMartin gravatar imageKarlMartin ( 2013-06-18 09:35:57 -0600 )edit

No, i do NOT use CrossCheck. I manually make the Ratio Test to discard results with the first and second match with similar "distance" values. The threshold is: firstmatch.distance /secondmatch.distance < 0.75. In this case i save the first match in my "good matches". However this is totally indipendent, because I simply delete some matches, but in the single (best) matches there are duplicate query indexes and duplicate train indexes.

ShadowTS gravatar imageShadowTS ( 2013-06-18 16:34:40 -0600 )edit