原文链接:http://www.juzicode.com/python-error-opencv-pencilsketch-mat-is-not-a-numerical-tuple
错误提示:
OpenCV pencilSketch绘制素描风格图像提示mat is not a numerical tuple
#VX公众号: 桔子code / juzicode.com
import cv2
print('cv2.__version__:',cv2.__version__)
img = cv2.imread('lvyi10.jpg')
img1=cv2.pencilSketch(img,sigma_s=10,sigma_r=0.9,shade_factor = 0.02)
cv2.imshow('img1',img1)
cv2.waitKey()
cv2.destroyAllWindows()
==========运行结果:
cv2.__version__: 4.5.3
---------------------------------------------------------------------------
error Traceback (most recent call last)
<ipython-input-1-2aa7eb62f234> in <module>
5 img = cv2.imread('lvyi10.jpg')
6 img1=cv2.pencilSketch(img,sigma_s=10,sigma_r=0.9,shade_factor = 0.02)
----> 7 cv2.imshow('img1',img1)
8 cv2.waitKey()
9 cv2.destroyAllWindows()
error: OpenCV(4.5.3) :-1: error: (-5:Bad argument) in function 'imshow'
> Overload resolution failed:
> - mat is not a numerical tuple
> - Expected Ptr<cv::cuda::GpuMat> for argument 'mat'
> - Expected Ptr<cv::UMat> for argument 'mat'
错误原因:
1、pencilSketch()返回的图像是一个元组,包含2个图像,导致imshow()显示错误。
解决方法:
1、用2个变量img1和img2接收pencilSketch()返回的图像,2个图像分别用imshow显示。
#VX公众号: 桔子code / juzicode.com
import cv2
print('cv2.__version__:',cv2.__version__)
img = cv2.imread('lvyi10.jpg')
#img1=cv2.pencilSketch(img,sigma_s=10,sigma_r=0.9,shade_factor = 0.02)
img1,img2=cv2.pencilSketch(img,sigma_s=10,sigma_r=0.9,shade_factor = 0.02)
cv2.imshow('img1',img1)
cv2.imshow('img2',img2)
cv2.waitKey()
cv2.destroyAllWindows()
扩展内容:
如果本文还没有完全解决你的疑惑,你也可以在微信公众号“桔子code”后台给我留言,欢迎一起探讨交流。