14

When I use fswebcam to capture a JPEG image from my webcam (an HP 2100) that is USB attached, it is always black?

1
  • 1
    Try the command fswebcam -d /dev/video0 -r 640x480 -v -S 10 --set brightness=100% test_image.jpg Apr 10, 2019 at 13:37

2 Answers 2

25

When we use fswebcam to grab an image, it appears that the camera is initialized, grabs an image and then disconnected. Some webcams have function to automatically balance their brightness. For example, in a dark room they sense that the brightness needs increased while in a bright area, the brightness may need to be decreased. The camera does this by examining its own frames and analyzing them. When a grab of an image occurs immediately after the camera is initialized, it hasn't seen enough data to know how bright the environment is and it appears that it assumes that the environment is SUPER bright and turns down its exposure control to minimum (resulting in a black image). As more frames are examined, the camera quickly adjusts its exposure settings.

To use fswebcam, we can supply it the option of -S <num> which is the number of frames that the camera should "see" and "skip" before it captures the image you want. I find that if I supply a skip of 20 the camera has had enough frames to self adjust its exposure and since we are processing 30 frames a second, that is still less than a second delay for grabbing 1 frame. For video streaming, we shouldn't have the problem as the camera will be initialized and stay initialized.

3
  • Skip at least 20 frames. I didnt get any improvements when skipping just 5 :-)
    – Ayman
    Apr 1, 2016 at 14:41
  • this -S skip fixed my issue of flickering, where some images were dim and others were the proper brightness. Thank you! Jun 23, 2019 at 6:26
  • I found that -S 2 is sufficient on my Logitech, with a Raspberry Pi 4B. 1 frame left a stripe artifact. 20 frames is rather slow. But whatever works... thanks for an excellent answer. Feb 21, 2021 at 20:34
2

You need to skip first few frames before capturing image, for more info see the blog post here

1
  • 1
    Since external links can disappear, would you mind capturing the necessary details from that post into your answer? This would allow others to find the answer on this site without having to click through. Use the correct attribution if needed.
    – Phil B.
    Oct 3, 2015 at 1:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.