# Revision history [back]

### 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
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'

 2 retagged LBerger 8919 ●1 ●17 ●81 http://perso.univ-lema...

### 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
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'