raspberrypi / picamera2

New libcamera based python library
BSD 2-Clause "Simplified" License
775 stars 164 forks source link

[SUGGESTION] Set maximum allowable shutter speed #634

Open GuidoBartoli opened 1 year ago

GuidoBartoli commented 1 year ago

Is your feature request related to a problem? Please describe. Using the picamera2 API, I did not find a way to set a maximum shutter time while retaining the AGC algorithm.

Describe the solution you'd like The camera controls should expose the "AeMaxShutter" parameter to be set by set_controls() method equivalent to the SetMaxShutter() method from AgcAlgorithm class API detailed in the Camera Algorithm and Tuning Guide (page 29).

Describe alternatives you've considered For my application, I need the maximum exposure time to be no more than 1/400 s to avoid motion blur when capturing a moving object. However, I would also like that, if the lighting is sufficient, the AGC algorithm can use shorter times and smaller analog gains to avoid overexposure (a behavior similar to the "Auto-ISO" mode with the "Min shutter" option enabled in traditional cameras).

Since the default "short" exposure mode allows the shutter time to climb up to 120000 us (~1/8 s), I had to manually set the values of exposure_modes within the JSON tuning file to set an upper limit. This is how I changed the "short" mode to achieve a maximum shutter time of 1/400 s:

"short":
{
    "shutter": [ 100, 600, 1000, 1500, 2000, 2500 ],
    "gain": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]
}

Additional context Nothing to add.

davidplowman commented 1 year ago

Hi, indeed libcamera does not have a control for setting the max shutter, but for Raspberry Pi sensors we define this in the tuning file. Editing the tuning file would be the correct thing to do.

GuidoBartoli commented 1 year ago

Does the tuning file expose a max_shutter value or it is a consequence of changing exposure modes as I did?

davidplowman commented 1 year ago

The exposure modes define the maximum shutter time. Though note that setting the framerate would limit the shutter time too (for example, at 30fps you can't have more than 33ms even if the exposure mode would allow higher), but it doesn't sound like this is an issue in your case!

GuidoBartoli commented 1 month ago

Describe the solution you'd like The camera controls should expose the "AeMaxShutter" parameter to be set by set_controls() method equivalent to the SetMaxShutter() method from AgcAlgorithm class API detailed in the Camera Algorithm and Tuning Guide (page 29).

Is there any news about the equivalent in picamera2 (Python) of the SetMaxShutter() function of libcamera (C++)? Both Raspberry Pi 5 and the Global Shutter Camera have recently come out, but still this functionality does not seem to be present in the latest version of picamera2.

davidplowman commented 1 month ago

Thanks for the suggestion. You're right that it might be nice to be able to do this at runtime, however, SetMaxShutter() is a Raspberry Pi specific function, and libcamera normally likes controls to be platform independent. So I don't think we'd have any plans to add anything like this just at the moment, given that it would have to be some kind of vendor specific control. Are there any particular use cases that something like this would enable, and which you can't achieve by editing the exposure modes? Thanks!