Ask Your Question
2

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)
cv2.waitKey(0)

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

Comments

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
1

I can do this :

 t=cv.cvtColor([3.1415926],cv.COLOR_BGR2GRAY)
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
1

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

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

1 answer

Sort by ยป oldest newest most voted
-1

answered 2019-03-17 20:39:10 -0500

supra56 gravatar image

updated 2019-03-18 07:46:52 -0500

I had same error, but I was doing distance from camera to object.And I solved it problem by using cv2.COLOR_BGR2GRAY.

gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)

to:

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

If this doesn't work. Try this:

gray = cv2.cvtColor(cv2.UMat(image), cv2.COLOR_RGB2GRAY)

This will solved your error problem.

edit flag offensive delete link more

Comments

And here is link: cv2.UMat

supra56 gravatar imagesupra56 ( 2019-03-18 07:55:06 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-03-15 17:16:20 -0500

Seen: 12,292 times

Last updated: Mar 18