Reputation: 1936
When I try to do the following:
cv2.drawMatches(img1, keypoints1, img2, keypoints2, matches, None, matchColor=(0,255,0), singlePointColor=(0, 0, 255))
I get this error:
error: OpenCV(4.1.0) ../modules/features2d/src/draw.cpp:127: error: (-2:Unspecified error) in function 'void cv::_prepareImage(cv::InputArray, const cv::Mat&)' Unsupported source image: 'src.type() == CV_8UC1 || src.type() == CV_8UC3 || src.type() == CV_8UC4' where 'src.type()' is 21 (CV_32FC3)
This error wasn't occurring yesterday and I didn't update the environment or the images. How can I fix this error? Not sure how to properly convert it.
I can see that the error occurs from here, but not sure what source type is expected.
Upvotes: 3
Views: 2059
Reputation: 1936
I simply had to convert the image types as follows:
cv2.drawMatches(np.uint8(img1), keypoints1, np.uint8(img2),
keypoints2, matches, None, matchColor=(0,255,0), singlePointColor=(0, 0, 255))
Upvotes: 2
Reputation: 338
The function _prepareImage seems to accept CV_8UC1 this types is 8U: Unsigned int 8-bit, C1: 1 channels. However, it seems you're sending a 32F, so 32 bit, with 3 channels.
where 'src.type()' is 21 (CV_32FC3)
Verify the type of the image you have and assign it accordingly.
Upvotes: 2