cv2.error: OpenCV(4.5.1) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-r2ue8w6k\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
安装好opencv进行测试时,发生以下错误
import cv2
img = cv2.imread("E:/pythonProject/mei.jpg")
cv2.imshow("hia", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
运行后,报错,看网上说时路径的问题,修改路径无果
Traceback (most recent call last):
File "E:/pythonProject1/demo.py", line 4, in <module>
cv2.imshow("hia", img)
cv2.error: OpenCV(4.5.1) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-r2ue8w6k\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
Process finished with exit code 1
仔细检查之后发现时图片格式不正确,图片格式是JPEG格式,将图片后缀改成JPEG格式就好了