OpenCV Error: (-215)size.width>0 && size.height>0 in function imshow
Solution 1:
This error message
error: (-215)size.width>0 && size.height>0 in function imshow
simply means that imshow() is not getting video frame from input-device. You can try using
cap = cv2.VideoCapture(1)
instead of
cap = cv2.VideoCapture(0)
& see if the problem still persists.
Solution 2:
I have the same problem, fix the ret in capture video
import numpy as np
import cv2
# Capture video from file
cap = cv2.VideoCapture('video1.avi')
while True:
ret, frame = cap.read()
if ret == True:
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame',gray)
if cv2.waitKey(30) & 0xFF == ord('q'):
break
else:
break
cap.release()
cv2.destroyAllWindows()
Solution 3:
I had this problem.
Solution: Update the path of the image.
If the path contains (for example: \n or \t or \a
) it adds to the corruption. Therefore, change every back-slash "\" with front-slash "/" and it will not make create error but fix the issue of reading path.
Also double check the file path/name. any typo in the name or path also gives the same error.