opencv-python 基本 ORB 特征检测在函数 cv::drawKeypoints 中给出错误 -215

opencv-python basic ORB feature detection gives me error -215 in function cv::drawKeypoints

这是来自 opencv-python 文档的基本代码:

import numpy as np
import cv2
from matplotlib import pyplot as plt

img = cv2.imread('simple.jpg',0)

# Initiate STAR detector
orb = cv2.ORB()

# find the keypoints with ORB
kp = orb.detect(img,None)

# compute the descriptors with ORB
kp, des = orb.compute(img, kp)

# draw only keypoints location,not size and orientation
img2 = cv2.drawKeypoints(img,kp,color=(0,255,0), flags=0)
plt.imshow(img2),plt.show()

它给了我这个错误:

Traceback (most recent call last):
File "C:\Python27\test.py", line 18, in <module>
img2 = cv2.drawKeypoints(img,kp,color=(0,255,0), flags=0)
error: ..\..\..\..\opencv\modules\features2d\src\draw.cpp:115: error:       (-215) !outImage.empty() in function cv::drawKeypoints

我不得不提到这个错误发生在 opencv-PYTHON,你能帮我解决一下吗?努力让它发挥作用

我找到了解决办法 找不到图片

我变了

img = cv2.imread('simple.jpg',0)

img = cv2.imread('c:\python27\sample.jpg', cv2.IMREAD_GRAYSCALE)

成功了

请注意,我用于示例图像的图像是我自己的灰度图像之一。