Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I've came across with thus issue also. I tried to avoid it but I was needed that cross-check. You can see the matches results:

BFMatcher matcher(NORM_L2):
-- Max dist : 1.656894 
-- Min dist : 0.855967 
0. distance: 0.906053, imgIdx: 0, queryIdx: 0, trainIdx: 14
1. distance: 1.11377, imgIdx: 0, queryIdx: 1, trainIdx: 20
2. distance: 0.998074, imgIdx: 0, queryIdx: 2, trainIdx: 14
3. distance: 1.65689, imgIdx: 0, queryIdx: 3, trainIdx: 5
4. distance: 1.04289, imgIdx: 0, queryIdx: 4, trainIdx: 14
5. distance: 1.45203, imgIdx: 0, queryIdx: 5, trainIdx: 6
6. distance: 1.60162, imgIdx: 0, queryIdx: 6, trainIdx: 6
7. distance: 0.968847, imgIdx: 0, queryIdx: 7, trainIdx: 56
8. distance: 0.900678, imgIdx: 0, queryIdx: 8, trainIdx: 56
9. distance: 0.855967, imgIdx: 0, queryIdx: 9, trainIdx: 88
10. distance: 1.29085, imgIdx: 0, queryIdx: 10, trainIdx: 88
11. distance: 1.49221, imgIdx: 0, queryIdx: 11, trainIdx: 43
12. distance: 1.2633, imgIdx: 0, queryIdx: 12, trainIdx: 103
13. distance: 1.36239, imgIdx: 0, queryIdx: 13, trainIdx: 43
14. distance: 1.54558, imgIdx: 0, queryIdx: 14, trainIdx: 88
15. distance: 0.980541, imgIdx: 0, queryIdx: 15, trainIdx: 103

BFMatcher matcher(NORM_L2,1):
-- Max dist : 0.775846 
-- Min dist : 0.000000 
0. distance: 0.191887, imgIdx: 0, queryIdx: 0, trainIdx: 14
1. distance: 0.236683, imgIdx: 0, queryIdx: 1, trainIdx: 20
2. distance: 0.775846, imgIdx: 0, queryIdx: 2, trainIdx: 150
3. distance: 0.58364, imgIdx: 0, queryIdx: 3, trainIdx: 119
4. distance: 0.54844, imgIdx: 0, queryIdx: 4, trainIdx: 137
5. distance: 0.375308, imgIdx: 0, queryIdx: 5, trainIdx: 44
6. distance: 0.292175, imgIdx: 0, queryIdx: 6, trainIdx: 6
7. distance: 0.33761, imgIdx: 0, queryIdx: 7, trainIdx: 40
8. distance: 0.217681, imgIdx: 0, queryIdx: 8, trainIdx: 56
9. distance: 0.173051, imgIdx: 0, queryIdx: 9, trainIdx: 88
10. distance: 0.317514, imgIdx: 0, queryIdx: 10, trainIdx: 97
11. distance: 0.526101, imgIdx: 0, queryIdx: 12, trainIdx: 107
12. distance: 0.394886, imgIdx: 0, queryIdx: 13, trainIdx: 43
13. distance: 0.444844, imgIdx: 0, queryIdx: 14, trainIdx: 17
14. distance: 0.210094, imgIdx: 0, queryIdx: 15, trainIdx: 103
15. distance: 1.96182e-44, imgIdx: 0, queryIdx: 1063263759, trainIdx: 265

(which give me the next error when it try to draw matches: OpenCV Error: Assertion failed (i1 >= 0 && i1 < static_cast<int>(keypoints1.size())) in drawMatches, file /home/eran/opencv-2.4.6.1/modules/features2d/src/draw.cpp, line 207)

I've solved it by removing it from my good_matches

  • imgIdx - sometimes wrong sometimes ok
  • queryIdx & trainIdx - most of times garbaged only in one side
  • distance - always somwething very small. in this case: 1.96182e-44

I added this code to min-max loop and the good_matches loop:

if (matches[i].distance < 0.00001) continue;

I hope that this number 0.00001 will catch all cases.

Or someone will fix this knn match bug :~