AttributeError: ‘NoneType’ object has no attribute 'shape’

img = cv2.imread(path)
height,width= img.shape[:2]

然后报如题所示错误。
经过检查发现是python中图像不存在
原因:
1.图片不存在(路径不存在, 路径包含中文无法识别)
查看路径,必要时,请将中文路径改为英文路径

2.读取的图片内容和默认读取时参数匹配不匹配。(默认读取的是3通道的彩色图)
例如读取到的图片是灰度图,就会返回None。

AttributeError: module ‘cv2’ has no attribute 'imread’
主要原因是程序命名为cv.py或者cv2.py,只需将改为其他的就可以啦

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐