首页 > 解决方案 > 读取和扭曲图像(-215:断言失败)size.width>0 && size.height>0 in function 'cv::imshow'

问题描述

import cv2

img =cv2.imread('OIP.jpg')

cv2.imshow("oip" , img)
cv2.waitkey(0)

cv2.imwrite('OIP.png', img)
cv2.destroyAllWindows()

这是错误

runfile('C:/Users/user/reading and writing an image.py', wdir='C:/Users/user')
Traceback (most recent call last):

 File "C:\Users\user\reading and writing an image.py", line 13, in <module>
   cv2.imshow("oip" , img)

error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) 
size.width>0 && size.height>0 in function 'cv::imshow'

标签: pythonopencv

解决方案


你能说你的img价值不为空吗?(此错误表明您的文件不存在)

例如:

import numpy as np

print(len(np.shape(img))) #should be equals or greater 2 

此致


推荐阅读