Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Expected cv::UMat for argument 'src'

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'

Expected cv::UMat for argument 'src'

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'