OpenCV detect camera but return no image feed, while guvcview does

421 Views Asked by At

Currently, I'm running some python code on my Ubuntu VM. The VM detects and connects to my Logitech C920, Here is the code I used to connect to the cam:

stream = cv2.VideoCapture(-1)
time.sleep(10.0)
if not (stream.isOpened()):
    print("Failed to get Video Capture")

I gave it 10 secs just to make sure that the cam fully loads before extracting the frame from the live feed. I used cv2.imshow() to view the frame and it is all black even though the camera is connected and greenlit when the code ran.

I noticed that the app Cheese has the same problems while guvcview works fine. Does anyone have any ideas about what may happen? Its been a couple days since I stuck with this problem so any help would be fantastic!

P.S: I found a relevant question on Stack overflow as well: Webcam doesn't read through OpenCV but does with guvcview but there is no answer yet

1

There are 1 best solutions below

1
On

Try setting indices other than -1 :

import cv2 ,time
stream = cv2.VideoCapture(0)
time.sleep(10.0)
if not (stream.isOpened()):
    print("Failed to get Video Capture")
else:
    while(True): 
        ret, frame = stream.read() 
        cv2.imshow('frame', frame) 
        if cv2.waitKey(1) & 0xFF == ord('q'): 
            break