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'
您的
img
值不为空吗? (此错误表明,您的文件不存在)
例如:
import numpy as np
print(len(np.shape(img))) #should be equals or greater 2