Search code examples
pythonopencvorb

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


this is the basic code from opencv-python documentation:

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

and it gives me this error:

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

i have to mention this error happens in opencv-PYTHON, can you help me out please? struggling really to make it work


Solution

  • i've found the solution it couldn't find the image

    i changed

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

    to

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

    and it worked

    note that the image i used for the sample image was one of my own grayscale images.