OpenCV错误:drawKeypoints中的断言失败(!outImage.empty()),

时间:2016-12-13 15:54:53

标签: python opencv sift

我正在学习SIFT algorithm以便比较图像和检测常见对象。 我正在这个领域开始,我正在编写一个小脚本来获取第一个关键点,但是我收到了错误。

我的剧本:

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)

我想显示包含所有关键点的灰色图片,但是我收到以下错误:

(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

我读过这篇文章:TypeError: Required argument 'outImg' (pos 6) not found

所以我在None内添加了drawKeypoints,但无法取得好成绩。

你有什么想法吗?

我正在处理Python 2.7OpenCV 3.1

谢谢;)

编辑:

如果我只是写下这几行:

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

我收到此错误:

TypeError: Image data can not convert to float

0 个答案:

没有答案