【发布时间】:2019-03-15 23:20:05
【问题描述】:
我正在尝试在图像上应用 canny 函数,这是完整的代码,但只有当我将步骤放在函数中时它才会显示错误,但在将所有代码留在任何函数之外时不会显示。代码:
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)
这是我得到的错误:(python 3.6.8)
kream@KRIMZON:~/Desktop/finding-lanes-linux$ python3 lane.py
Traceback (most recent call last):
File "lane.py", line 12, in <module>
cannyer = canny(img)
File "lane.py", line 5, in canny
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
TypeError: Expected cv::UMat for argument 'src'
kream@KRIMZON:~/Desktop/finding-lanes-linux$
【问题讨论】:
-
问题已修复,在我使用原始图像的变量而不是我制作的实际副本后发现原始图像被我错误地损坏/修改后,通过替换修复原始图像并确保它不会再次发生,感谢阅读。
-
太棒了,你自己解决了这个问题 :) -- 但是为了使它有用,要么写一个自我回答,要么删除问题。
-
由于某种原因,它不允许我在 48 小时之前写出自我回答。
标签: python python-3.x opencv