Manual exposure time (and auto gain and WB)

My aim is to enforce a short exposure time (of 10000 us) to freeze the motion of fast objects when detecting (with frame differencing) them in an environment with changing lights. Thus, I need exposure control while white balance and gain are still automatic, just like in any camera “S” (shutter speed) control mode.

I thought it would be enough to do:
exposure_us = 10000)
and then the camera would automatically adjust the gain to keep obtaining a bright enough image in all conditions, since white balance and gain are automatic by default?

However, when doing this, the somehow the image keeps being dark, and I don’t want to set a manual gain dB value due to the changing light. Is it the night_mode that causes problems?

The camera’s a cellphone camera… it’s not really going to wow you with it’s ability to run on very little exposure.

Yes, the camera will dynamically adjust it’s gain. However, you have to raise the gain ceiling: sensor — camera sensor — MicroPython 1.15 documentation

Note that noise goes WAY UP when you max it out.

Thanks @kwagyeman . I am fine with the usual limitations of small sensors.

However, raising the gain ceiling to its maximum does not really do what is expected.

I used:

sensor.set_auto_exposure(False, \
    exposure_us = custom_exposure)
sensor.set_auto_gain(True, \
    gain_ceiling = 37)

I determined the gain ceiling from the maximum gain_dB I could set the sensor to manually when auto_gain is False (~ 36 dB).

For custom_exposure values between 10 000 and 160 000, I get very dark pictures. Starting from 170 000 us, the picture suddenly brightens up.

However, even though I tried all increments of 10 000 us in that range, when I reach the 170 ms threshold, the camera does not even go to its maximum gain_ceiling value that is possible, it only goes up to ~ 23 dB.

My non-expert interpretation is that the sensor does to even try to match the standard brightness when it is too hopelessly dark (below 170 ms exposure time in my special scene). It only tries to match the standard brightness when it has a chance to reach the standard brightness, BUT it does not even make use of its maximum gain_dB of 36 dB even though the gain_ceiling was set above that (at 37 dB).

Is something wrong? Could it be related to night mode? How can I make the camera brighten the picture as much as it can to reach a standard brightness, and make use of its maximum gain level with auto_gain?

Here are two pictures showing the transition over that threshold value:

gain_dB: 6.0207 , exposure_us: 1.599690e+05:

gain_dB: 23.8066 , exposure_us: 1.699790e+05:

What sensor are you using? What camera model? We support a lot of different camera sensors… the code for our driver and the sensor datasheet is online. I’ll send you the link and you can look if I missed anything on the control.

Also, you can manually edit registers using sensor.__write_reg()/sensor.__read_reg().

sorry I forgot… I use the H7+ with the 5MP OV5645 sensor.
I’d be glad to get the info to edit camera registers if that is a solution.

See this:

Read on the datasheet how auto exposure and gain works. It’s quite complex for this sensor… and there are a bunch of undocumented parts with it.

Thanks, still trying to find the time to do this, will report back if successdul