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 );
Hi! I have the same problem. Im making a real time object detector and for unknown reason, the trainIdx gets higher values than the train keypoints vector size (randomly), throwing an OpenCv Exception... I could not find any explanation about this...
@yes123, could you please explain more