D:\python3.8\python.exe D:/pythonProject1/canny.py Traceback (most recent call last): File "D:/pythonProject1/canny.py", line 26, in <module> img_canny = canny(gray_smoothed, low_threshold, high_threshold) File "D:\python3.8\lib\site-packages\skimage\feature\_canny.py", line 314, in canny raise ValueError("low_threshold should be lower then high_threshold") ValueError: low_threshold should be lower then high_threshold 进程已结束,退出代码1
时间: 2024-02-06 10:09:32 浏览: 252
这个错误提示是因为你在调用canny函数时,传入的低阈值参数小于了高阈值参数。可以检查一下你传入的参数是否正确,或者尝试交换一下参数的位置。下面是一个示例代码:
```python
import cv2
import numpy as np
def canny(image, low_threshold, high_threshold):
return cv2.Canny(image, low_threshold, high_threshold)
if __name__ == '__main__':
img = cv2.imread('test.jpg', 0)
gray_smoothed = cv2.GaussianBlur(img, (3, 3), 0)
low_threshold = 50
high_threshold = 150
img_canny = canny(gray_smoothed, low_threshold, high_threshold)
cv2.imshow('Canny', img_canny)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
你可以将上述代码保存为canny.py,并且将一张图片命名为test.jpg放在相同的目录下,然后运行代码。
相关问题
D:\python3.8\python.exe D:/pythonProject1/bishe1.py 俯视or侧视:俯视 Traceback (most recent call last): File "D:/pythonProject1/bishe1.py", line 58, in <module> edge = cv.Canny(opening, 50, 160, color1=(255, 255, 255), color2=(0, 0, 255))#提取轮廓50,160 cv2.error: OpenCV(4.6.0) :-1: error: (-5:Bad argument) in function 'Canny' > Overload resolution failed: > - 'color1' is an invalid keyword argument for Canny() > - 'color1' is an invalid keyword argument for Canny() > - Canny() missing required argument 'threshold2' (pos 4) > - Canny() missing required argument 'threshold2' (pos 4) 进程已结束,退出代码1
根据你的描述,这是一段 Python 代码,使用了 OpenCV 库中的 Canny 函数进行轮廓提取。但是在调用 Canny 函数时,出现了错误。错误信息显示 Canny 函数的参数有误,可能是由于 color1 这个参数不被识别导致的。建议检查一下 Canny 函数的参数是否正确,并确认 color1 这个参数是否被正确识别。另外,还需要确认函数的其他参数是否正确设置,例如 threshold1 和 threshold2。
阅读全文