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!
PS: 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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.