Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webcam + Open CV Python | Black screen

I am using the code below, but I get a black image. Could you please help me rectify the error?

import cv2
import numpy as np
c = cv2.VideoCapture(0)

while(1):
    _,f = c.read()
    cv2.imshow('e2',f)
    if cv2.waitKey(5)==27:
        break
cv2.destroyAllWindows()
like image 437
Akanksha Dangi Avatar asked Oct 15 '25 10:10

Akanksha Dangi


2 Answers

Update: See github.com/opencv/opencv/pull/11880 and linked conversations, only few backends support -1 as index.


Although this is an old post, this answer can help people who are still facing the same problem. If you have a single webcam but it renders all black, use cv2.VideoCapture(-1). This will get you the working camera.

like image 171
Praveen Avatar answered Oct 17 '25 00:10

Praveen


Just change cv2.waitKey(0) to cv2.waitKey(30) and this issue will be resolved.

like image 32
Amit kumar Avatar answered Oct 17 '25 00:10

Amit kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!