Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to estimate exposure time for camera to take a good image from a scene

I am trying to write code to calculate the correct exposure time for a camera to capture an image in correct brightness.

what I have is a camera that supply me data in RAW (Bayer raw data) and I can control its exposure time, and I want to control its exposure so when it captured an image, the image is in correct brightness (not too dark (under exposed) or too bright (over exposed).

I think I need an algorithm similar to this:

1-capture a sample image
2-calculate image brightness.
3-calculate correct exposure.
4-capture a new image,
5-check that the image brightness is correct if not go to step 3.
6- capture final image.

My question is:

  1. How can I calculate image brightness?
  2. If I calculate image brightness, how can I calculate exposure? One way of doing this is to do a search (for example start from very fast exposure time increase it till you get a correct exposure, but It is a very time consuming, is there any better way of doing this?)
    1. To do this, I may need to calibrate my camera (as the relationship between brightness and exposure time is different between different sensors), how can I do this?

I am using OpenCV and I can use algorithms which is available in OpenCV (c++)

like image 266
mans Avatar asked Oct 30 '22 21:10

mans


1 Answers

There are multiple ways to measure the "correct" brightness of the image. A common method is to calculate the intensity histogram and make sure that the values cover the entire range of values, and there is not too much cut-off. I'm not sure if there's a single "one fit all" way for any possible scene.

enter image description here

A faster way than linearly increasing the exposure is to do a binary search, by measuring at low and high exposure, then measuring in the middle, and then continuing to split the sub-range in the middle, until you find the optimum.

like image 144
Photon Avatar answered Nov 15 '22 06:11

Photon