1

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
Community
  • 1
  • 1
Essex
  • 6,042
  • 11
  • 67
  • 139
  • Please check if the images you are reading in are really jpg's and not png's? Furthermore, if you want to read in an image as gray-scale, the parameter should be 0 not 1 as you specified it. – Kevin Katzke Dec 13 '16 at 22:04
  • @KevinKatzke My images are really in jpeg's format. The probleme is always with the `drawKeypoints function` – Essex Dec 14 '16 at 13:40
  • I'm sure that the problem lies in opencv not being able to load the gray image. Try to add `cv2.imwrite('test_gray.jpg',gray)` right after you load the gray image to see if the loading really works. – Kevin Katzke Dec 14 '16 at 13:54
  • I have always the same error : `OpenCV Error: Assertion failed (!outImage.empty()) in drawKeypoints, file /home/valentinjungbluth/opencv-3.1.0/modules/features2d/src/draw.cpp, line 113 Traceback (most recent call last): File "image.py", line 17, in img = cv2.drawKeypoints(gray,kp,img) cv2.error: /home/valentinjungbluth/opencv-3.1.0/modules/features2d/src/draw.cpp:113: error: (-215) !outImage.empty() in function drawKeypoints` Possible a bad openCV installation ? But it's strange – Essex Dec 14 '16 at 14:04
  • I added an edit part in my question – Essex Dec 14 '16 at 14:09

0 Answers0