Python错误集锦:OpenCV 滤波函数blur()提示:error: (-5:Bad argument) in function ‘blur’,Overload resolution failed: Can’t parse ‘ksize’. Input argument doesn’t provide sequence protocol

原文链接:http://www.juzicode.com/archives/6639

错误提示:

滤波函数blur()提示:error: (-5:Bad argument) in function ‘blur’,Overload resolution failed: Can’t parse ‘ksize’. Input argument doesn’t provide sequence protocol

#VX公众号:桔子code / juzicode.com
import cv2
print('cv2.__version__:',cv2.__version__)

img = cv2.imread('lena.jpg')
ret_img = cv2.blur(img,5) 
cv2.imshow('img',ret_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
==========运行结果:
cv2.__version__: 4.5.2
---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-7-043327fe9f55> in <module>
      4 
      5 img = cv2.imread('lena.jpg')
----> 6 ret_img = cv2.blur(img,5)
      7 cv2.imshow('img',ret_img)
      8 cv2.waitKey(0)

error: OpenCV(4.5.2) :-1: error: (-5:Bad argument) in function 'blur'
> Overload resolution failed:
>  - Can't parse 'ksize'. Input argument doesn't provide sequence protocol
>  - Can't parse 'ksize'. Input argument doesn't provide sequence protocol

错误原因:

1、blur()的第2个位置参数不是单个数值,应该是包含2个数值的tuple或者list。

解决方法:

1、修改blur()的第2个位置参数为tuple或list:

#VX公众号:桔子code / juzicode.com
import cv2
print('cv2.__version__:',cv2.__version__)

img = cv2.imread('lena.jpg')
ret_img = cv2.blur(img,(5,5))
#ret_img = cv2.blur(img,[5,5]) 
cv2.imshow('img',ret_img)
cv2.waitKey(0)
cv2.destroyAllWindows()

扩展内容:

  1. OpenCV-Python教程


如果本文还没有完全解决你的疑惑,你也可以在微信公众号“桔子code”后台给我留言,欢迎一起探讨交流。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注