错误的原因是cv.imshow这个函数
搜这个问题的时候发现很多博客在胡扯,这个函数的第一个参数根本不是什么地址
cv2.imshow('显示窗口名称',图像数组)
def imshow(winname, mat): # real signature unknown; restored from __doc__
"""
. - If the image is 8-bit unsigned, it is displayed as is.
. - If the image is 16-bit unsigned, the pixels are divided by 256. That is, the
. value range [0,255\*256] is mapped to [0,255].
. - If the image is 32-bit or 64-bit floating-point, the pixel values are multiplied by 255. That is, the
. value range [0,1] is mapped to [0,255].
. - 32-bit integer images are not processed anymore due to ambiguouty of required transform.
"""
解决方案:
其中图像数组是numpy类型,如果是RGB三通道类型的,数组大小为:图像长*图像宽*3
若出现报错,先检查是不是图像数组有问题,改成规定格式就能成功解决
注:
cv.show()函数测试
import cv2
img=cv2.imread('2007_000876.jpg')
cv2.imshow("img", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
参考资料:
下面这个错误原因是,变量名不能重复使用