Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

cv2.drawKeypoints not drawing keypoints on the outImage

I am working with OpenCV in Python and trying to diplay the keypoints recognized by SIFT from gray image to the original color image. Here is my code

import cv2 as cv

org_img = cv.imread('/content/Sunset_org.jpg')
gray_img = cv.cvtColor(org_img,cv.COLOR_BGR2GRAY)

sift = cv.SIFT_create()
kp = sift.detect(gray_img,None)
sift = cv.drawKeypoints(gray_img, kp, outImage=org_img, flags=cv.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
cv.imshow('Sift Img', sift)
cv.waitKey(0)

I want the keypoints to be drawn on the original image, but instead it is being diplayed on the gray image. Did I misunderstand the use of the third argument, i.e. outImage? What am I doing wrong?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

To see where keypoints are located, you need to use original image as a background. This is the first argument of cv.drawKeypoints function. The third one is the output image (keypoints + original image). Output image is returned. This API is strange but to draw keypoints properly use following syntax:

sift = cv.drawKeypoints(org_img, kp, 0, flags=cv.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading