Can't read frame with webcam. Error -2147483638

Viewed 912

I want to read video from webcam with helps opencv on python but I have next error:

'NoneType' object has no attribute 'shape'.

In console I have: [ WARN:0] videoio(MSMF): can't grab frame. Error: -2147483638

print("starting video stream...")
vs = VideoStream(src=0).start()
time.sleep(2.0)

while True:
    frame = vs.read()
    frame = imutils.resize(frame, width=600)    #'NoneType' object has no attribute 'shape'

    if W is None or H is None:
        (H, W) = frame.shape[:2]

    cv2.imshow("Frame", frame)
    key = cv2.waitKey(1) & 0xFF

    if key == ord("q"):
        break

cv2.destroyAllWindows()
vs.stop()

Hay can I solve this problem? Thanks!

2 Answers

the default MSMF api for camera wasnt working for me with opencv 4.2.0.34, but works for opencv 3. switching to DSHOW api worked

cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)

I have noticed the issue was resolved using the following steps (found here):

I managed to get around the issue, I uninstalled the LM driver via Device Manager, and reinstalled. I also made sure the LM Control Panel app was NOT running. Now, it seems to work fine. Not sure which fixed it.

Related