Question

Basically I have:

BruteForceMatcher<L2<float>>().knnMatch(descriptor1,descriptor2,matches,2);

To get only good matches I parse all the "matches" vectors and check the distance like this:

if( (matches[i][0].distance / matches[i][1].distance) < ratio ){
  //> Good match!
}

But what matches[i][0].distance mean ? The distance between matches[i][0] and ?

My supposition

For what I could guess it would sound more logic to me to calculate the euclian distance between the first match with it's NN, and filter it with a threshold, something like:

//> I calculate the distance between 2 nearest neighborhood and filter it based on thresold
foreach( matches : i) {
 if ( euclianDistance( matches[i][0] , matches[i][1] ) < threshold ) {
   //> good match
 }
}
Was it helpful?

Solution

descriptor - is a point of N-dimensional space.

match - is a pair of descriptors - one from the first set and one from the second set (also called train and query sets).

distance - is a L2 metric for 2 descriptors pointed by the match structure. (You are specifying the type of metric as a template parameter for BruteForceMatcher).

match[i][0].distance = L2(descriptor1.row(match[i][0].trainIdx),
                          descriptor2.row(match[i][0].queryIdx))

So knnMatch returns two closest descriptors from the query set for every descriptor from the train set. Next you are filtering out cases when the two found descriptors are close to each other.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top