0

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 Answers1

0

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   
Subasri sridhar
  • 809
  • 5
  • 13
  • Thanks. I tried with 0 and some other indexes already. The code detects and triggers the camera as the LED on the cam lit up, but still no image – Minh Duc Pham Oct 05 '20 at 16:33