I'm learning SIFT algorithm
in order to compare images and detect common objects.
I'm beginning in this domain and I'm writing a little script to get Keypoints in firstime but I get an error.
My script :
import numpy as np
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('test.jpg') # trainImage
gray = cv2.imread('test.jpg',1)
# Initiate SIFT detector
sift = cv2.xfeatures2d.SIFT_create()
kp = sift.detect(gray,None)
img = cv2.drawKeypoints(gray,kp,None)
cv2.imwrite('sift_keypoints.jpg',img)
I want to display the gray picture with all keypoints, but I get the following error :
(cv) valentin@ubuntu:~/Desktop$ python image.py
OpenCV Error: Assertion failed (!outImage.empty()) in drawKeypoints, file /home/valentin/opencv-3.1.0/modules/features2d/src/draw.cpp, line 113
Traceback (most recent call last):
File "image.py", line 13, in <module>
img = cv2.drawKeypoints(gray,kp,None)
cv2.error: /home/valentin/opencv-3.1.0/modules/features2d/src/draw.cpp:113: error: (-215) !outImage.empty() in function drawKeypoints
I read this post : TypeError: Required argument 'outImg' (pos 6) not found
So I added None
inside drawKeypoints
but impossible to get a good result.
Do you have an idea ?
I'm working on Python 2.7
and OpenCV 3.1
Thank you ;)
EDIT :
If I just write this some lines :
img = cv2.imread('/home/valentin/Bureau/ville.jpg')
gray = cv2.imread('ville.jpg',0)
cv2.imwrite('test_gray.jpg',gray)
plt.imshow(img), plt.show()
I get this error :
TypeError: Image data can not convert to float