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?
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)