opencv显示图片报错_opencv打开图片报错

code:

import cv2

img = cv2.imread("D:\123.jpg")

cv2.namedWindow("Image")

cv2.imshow("Image", img)

cv2.waitKey(0)

cv2.destroyAllWindows()报错:

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file ..\..\..\opencv-3.1.0\modules\highgui\src\window.cpp, line 289

Traceback (most recent call last):

File "C:/Users/zyj/untitled6/opencv.py", line 5, in

cv2.imshow("Image", img)

cv2.error: ..\..\..\opencv-3.1.0\modules\highgui\src\window.cpp:289: error: (-215) size.width>0 && size.height>0 in function cv::imshow

解决办法:

将图片路径,即代码第二行img = cv2.imread("D:\123.jpg")改为

img = cv2.imread("D:\\123.jpg") #两个斜杠

你可能感兴趣的:(opencv显示图片报错)