Ask Your Question

Revision history [back]

Can't read camera feed

I am new to Python, and I am trying to get OpenCV 3.2.0 running on my Windows 10 machine with a Logitech C920

The script will pop up a Video Source dialog where I select my Logitech C920. The little blue light on that indicates that its being accessed turns on, but the cap.read() call always returns false. If I run the same code using the vtest.avi video file, it runs fine

Whats going on? Why can't I read the frames from the live webcam? If I switch the camera to use the one in my HTC Vive it gets the frames and shows a window, but the image data is always black. Both cameras work fine if I check them in Google Hangouts

Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)] on win32

OpenCV 3.2.0

import numpy as np
import cv2

#cap = cv2.VideoCapture("vtest.avi");
cap = cv2.VideoCapture(-1);

while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()
    print cap.isOpened(), ret
    if frame is not None:
        # Display the resulting frame
        cv2.imshow('frame',frame)
        if cv2.waitKey(22) & 0xFF == ord('q'):
            break
    else:
        print "Frame is None"

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
print "I am done"