cv2.error: OpenCV(3.4.7) D:\Build\OpenCV\opencv-3.4.7\modules\highgui\src\window.cpp:366: error: (-2

Traceback (most recent call last):
  File "C:/project/ztplan/renlian/test1.py", line 4, in
    cv2.imshow('image',img)
cv2.error: OpenCV(3.4.7) D:\Build\OpenCV\opencv-3.4.7\modules\highgui\src\window.cpp:366: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'

 

cv2.error: OpenCV(3.4.7) D:\Build\OpenCV\opencv-3.4.7\modules\highgui\src\window.cpp:366: error: (-2_第1张图片

路径问题,cv2不识别相对路径

 

改为绝对路径即可

cv2.error: OpenCV(3.4.7) D:\Build\OpenCV\opencv-3.4.7\modules\highgui\src\window.cpp:366: error: (-2_第2张图片

 

代码:

import cv2
img = cv2.imread('C:/project/ztplan/1.jpg')
#C:/project/ztplan
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

cv2 版本链接:

下载opencv_python

下载网址:https://www.lfd.uci.edu/~gohlke/pythonlibs/

cd 到下载文件目录下

在命令行中输入pip install opencv_python-3.4.5-cp37-cp37m-win_amd64.whl

刷新pycharm 等一会便加载成功了

 

你可能感兴趣的:(深度学习)