读取和扭动图像(-215:断言失败)函数'cv :: imshow'中的size.width> 0 && size.height> 0 [重复]

问题描述 投票:0回答:1
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'
python opencv
1个回答
0
投票

您的

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

例如:

import numpy as np

print(len(np.shape(img))) #should be equals or greater 2 
© www.soinside.com 2019 - 2024. All rights reserved.