Expected cv::UMat for argument 'src'

asked 2019-03-15 17:18:05 -0500

iseegr8tfuldeadppl gravatar image

updated 2019-03-18 02:18:13 -0500

LBerger gravatar image

I'm trying to apply the canny function on an image and here's the full code but it shows the error only if i put the steps within a function, but doesn't show when leaving all the code outside of any functions. Code:

import cv2
import numpy as np

def canny(image):
    gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
    blur = cv2.GaussianBlur(gray, (5,5), 0)
    canny = cv2.Canny(blur, 50, 150) #sick
    return canny
sourceimage = cv2.imread('lane.jpg')
img = np.copy(sourceimage)
canny = canny(img)
cv2.imshow("result", canny)

And here is the error i get: (python 3.6.8)

Traceback (most recent call last):
  File "lane.py", line 12, in <module>
    canny = canny(img)
  File "lane.py", line 5, in canny
    gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
TypeError: Expected cv::UMat for argument 'src'
edit retag flag offensive close merge delete


cv2.__version__ ? how did you install that ?

i think, you found a bug here.

though, as with any python noob, you fall into the image-not-loaded-and-you-never-check pit,

the weird thing here is, that np.copy(None) triggers a different codepath than a plain None

berak gravatar imageberak ( 2019-03-18 04:13:04 -0500 )edit

I can do this :

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Expected cv::UMat for argument 'src'

pi is not compatible with UMat please check your data

LBerger gravatar imageLBerger ( 2019-03-18 04:36:30 -0500 )edit

cv2.cvtColor("helo, there !",...)

berak gravatar imageberak ( 2019-03-18 04:50:10 -0500 )edit