I've been trying to use the SIFT detector for about a week now and when I finally get it working, I get an error with the cv2.drawKeypoints()
function. The code is as follows:
import cv2
import numpy as np
img = cv2.imread('\\home\\gaiarsa\\matrix\\poste.jpg')
gray = cv2.imread('\\home\\gaiarsa\\matrix\\poste.jpg', 1)
sift = cv2.xfeatures2d.SIFT_create()
dummy = np.zeros((1,1))
kp = sift.detect(gray, None)
img = cv2.drawKeypoints(gray, kp,dummy, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
cv2.imwrite('sift_keypoints.jpg', img)
After I run it I get the error:
OpenCV Error: Assertion failed (!outImage.empty()) in drawKeypoints, file /home/gaiarsa/opencv/modules/features2d/src/draw.cpp, line 113
Traceback (most recent call last):
File "sift.py", line 14, in <module>
img = cv2.drawKeypoints(gray, kp,dummy, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
cv2.error: /home/gaiarsa/opencv/modules/features2d/src/draw.cpp:113: error: (-215) !outImage.empty() in function drawKeypoints
When I try removing the dummy
array from the function arguments, I get the following error:
Traceback (most recent call last):
File "sift.py", line 14, in <module>
img = cv2.drawKeypoints(gray, kp, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
TypeError: Required argument 'outImage' (pos 3) not found
The problem was reading a png file as a jpeg. As soon as I changed it, it worked