Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

drawMatches bug

I think there is a bug in drawMatches.cpp

OpenCV/modules/features2d/src/draw.cpp line: 208

There are two assert:

int i1 = matches1to2[m].queryIdx;
int i2 = matches1to2[m].trainIdx;
CV_Assert(i1 >= 0 && i1 < static_cast<int>(keypoints1.size()));
CV_Assert(i2 >= 0 && i2 < static_cast<int>(keypoints2.size()));

The problem is that keypoints1 refers to the train image, while i1 referers to the queryIdx.

I believe it should be inverted:

int i1 = matches1to2[m].trainIdx;
int i2 = matches1to2[m].queryIdx;

I believe this is a commont mistake in OpenCV because almost every samples use the wrong order to call DescriptorMatcher::match in fact there is always this error in the documentation:

obj.push_back( kp_object[ good_matches[i].queryIdx ].pt );  //> It should be trainIdx
scene.push_back( kp_image[ good_matches[i].trainIdx ].pt );