Search code examples
opencvsiftsurf

knnMatch requires k>1 to get good results?


I am using SURF and i am trying both

FlannBasedMatcher

and

BruteForceMatcher

I saw to get good matches I need to set

matcher.knnMatch(,,2); // with k=2 (At least)

If I set k = 1 I don't get the first less distant match for that keypoint.
Are there any reasons?


Solution

  • knnMatch partitions your data in k groups. If k=1, you will put it in one big group.

    With a single partition, it will be hard for the algorithm to figure out the distance to a second one. So there will be no distance to calculate at all.