Why are webcam images made with Python so dark?

I showed in many ways how to take images using a webcam in Python (see How can I take images using Python? ). You can see that images made using Python are significantly darker than images made using JavaScript. What's wrong?

Image example

The image on the left was taken using http://martin-thoma.com/html5/webcam/ , the following on the right: with the following Python code. Both were taken with the same (controlled) lightning situation (it was dark outside, and I only had electric lights) and the same webcams.

enter image description here

Code example

import cv2 camera_port = 0 camera = cv2.VideoCapture(camera_port) return_value, image = camera.read() cv2.imwrite("opencv.png", image) del(camera) # so that others can use the camera as soon as possible 

Question

Why is the image obtained with the Python image much darker than the one that was made using JavaScript, and how to fix it?

(Obtaining the same image quality, just its bright, may not be fixed.)

Pay attention to "how to fix it": it does not have to be opencv. If you know the ability to use webcam images using Python with another package (or without a package), this is also normal.

+5
python opencv
Feb 17 '15 at 17:06
source share
2 answers

I think you need to wait until the camera is ready.

This code works for me:

 from SimpleCV import Camera import time cam = Camera() time.sleep(3) img = cam.getImage() img.save("simplecv.png") 

I accepted the idea of this answer , and this is the most convincing explanation I found:

The first few frames on some devices are dark, because this is the first after the initialization of the camera, and it may take several frames for the camera to adjust the brightness automatically. link

Thus, IMHO, in order to be sure of the image quality, regardless of the programming language, when you start the camera device, you need to wait a few seconds and / or drop a few frames before shooting.

+6
Jan 08 '16 at 23:49
source share

Faced the same problem. I tried this and it works.

 import cv2 camera_port = 0 ramp_frames = 30 camera = cv2.VideoCapture(camera_port) def get_image(): retval, im = camera.read() return im for i in xrange(ramp_frames): temp = camera.read() camera_capture = get_image() filename = "image.jpg" cv2.imwrite(filename,camera_capture) del(camera) 

I think that it concerns the adjustment of the camera to light. Former old and later images

+4
Apr 7 '16 at 14:36
source share



All Articles