Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Webcam works inconsistently

Hello,

I have searched for answer to this error for a few days now as I have seen people getting the same error however none of the solutions I came across worked.
I created a simple program to do nothing other than load in the camera:

import cv2

cap = cv2.VideoCapture(0)

# Check if the webcam is opened correctly
if not cap.isOpened():
    raise IOError("Cannot open webcam")

while True:
    ret, frame = cap.read()
    cv2.imshow('Input', frame)

    c = cv2.waitKey(1)
    if c == 27:
        break

cap.release()
cv2.destroyAllWindows()

Though, sometimes my webcam loads in with no problems most of time doesn't work with the error messages:

[ WARN:0] videoio(MSMF): OnReadSample() is called with error status: -2147024894 [ WARN:0] videoio(MSMF): async ReadSample() call is failed with error status: -2147024894 [ WARN:1] videoio(MSMF): can't grab frame. Error: -2147024894 cv2.error: OpenCV(3.4.4) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:356: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow

I have seen many answers talk about the camera capture being empty and it not expecting an empty value: though they don't explain WHY it is empty and how to prevent it.

Any help is greatly appreciated.