OpenCV Error: (-215)size.width>0 && size.height>0 in function imshow OpenCV Error: (-215)size.width>0 && size.height>0 in function imshow python python

OpenCV Error: (-215)size.width>0 && size.height>0 in function imshow


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.


I have the same problem, fix the ret in capture video

import numpy as npimport cv2# Capture video from filecap = 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:        breakcap.release()cv2.destroyAllWindows()


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.