muth
Posts: 27
Joined: Sun Aug 05, 2012 3:32 pm

RaspYUV auto exposure (-ex night) extended

Fri Jun 26, 2015 11:47 pm

Hello!
Is it possible to let the auto exposure, with the option -night, to go a bit further in shutter speed and iso ?

For night sky, it go until a bit less than 1 second exposition and 400 iso. Manually, the results are nicer with 800 iso and more than 1 second exposition.

To be precise, what I'm looking for is to take picture continuously during day and night. It work nicely, even with the -ex night during daytime as the shutter speed and iso adapts. If the automatic exposure process could let the parameters go even more extreme, such as 6 seconds exposition and 800 iso, the total dynamic range would be great !

I imagine such process is done on the GPU part, I don't know if there is still development possible...

Anyway, thanks a lot for all these nice coding !

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 9254
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: RaspYUV auto exposure (-ex night) extended

Sat Jun 27, 2015 8:01 am

To exceed about 0.8s requires change of sensor mode, and the AGC algo doesn't have the option to do that.
It might be possible to set the FPS range to the long mode but leaving it on night exposure to give some reasonable results. The min exposure will be longer than normal, and you may suffer more rolling shutter artifacts, but worth a try. See raspistill source for where it checks the shutter speed and alters the FPS_RANGE, and just force it into the long mode always. The night exposure mode appears to be configured to allow up to 10s exposure times if the sensor mode allows, but I don't know if that will actually work or hit calculation overflows.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

muth
Posts: 27
Joined: Sun Aug 05, 2012 3:32 pm

Re: RaspYUV auto exposure (-ex night) extended

Sat Jun 27, 2015 10:18 am

Thank you very much for your fast reply !
It is a good news yet if the night exposure mode could be up to 10s.

In RaspiStill.c, do you talk about these lines, in the function :
create_camera_component(RASPISTILLYUV_STATE *state)

Code: Select all

if(state->camera_parameters.shutter_speed > 6000000)
   {
        MMAL_PARAMETER_FPS_RANGE_T fps_range = {{MMAL_PARAMETER_FPS_RANGE, sizeof(fps_range)},
                                                     { 50, 1000 }, {166, 1000}};
        mmal_port_parameter_set(still_port, &fps_range.hdr);
   }
   else if(state->camera_parameters.shutter_speed > 1000000)
   {
        MMAL_PARAMETER_FPS_RANGE_T fps_range = {{MMAL_PARAMETER_FPS_RANGE, sizeof(fps_range)},
                                                     { 167, 1000 }, {999, 1000}};
        mmal_port_parameter_set(still_port, &fps_range.hdr);
   }
And force

Code: Select all

MMAL_PARAMETER_FPS_RANGE_T fps_range = {{MMAL_PARAMETER_FPS_RANGE, sizeof(fps_range)},
                                                     { 167, 1000 }, {999, 1000}};
        mmal_port_parameter_set(still_port, &fps_range.hdr);
?

As far as I understood, fps_range need two rational types. Is { 167, 1000 }, {999, 1000} means a range between 167/1000 second and one second ?

To be honest, I'm not confident with compiling C++ codes on raspberry pi yet. I'll make some tests (with cmake if I'm correct), and let you know.

Thanks again for your help !

muth
Posts: 27
Joined: Sun Aug 05, 2012 3:32 pm

Re: RaspYUV auto exposure (-ex night) extended

Sat Jun 27, 2015 3:35 pm

Hi again,
I manage to build the sources and make changes in RaspiStill.c

I forced preview_port and still_port with

Code: Select all

MMAL_PARAMETER_FPS_RANGE_T fps_range = {{MMAL_PARAMETER_FPS_RANGE, sizeof(fps_range)},{167,1000 }, {999,1000}};
mmal_port_parameter_set(preview_port, &fps_range.hdr)
...
mmal_port_parameter_set(still_port , &fps_range.hdr);
I can see the preview getting very more sensible after an adaptation time (I suppose the time required by the AGC to adapt the darkness) and the FPS getting low (longer exposure time). I had to force a the delay with -t to about 30 seconds to let enough time to the AGC.
But when the picture is taken, it is difficult to interpret the parameters used. I manage to have a 2.4 seconds exposed picture, another with ISO 800, but not on a stable manner. Some time, for the same scene, it takes a dark picture with 1/2sec and ISO250.

I tried as well to force the FPS_RANGE of the preview_port only, and got the same behavior. I supposed only the preview_port is used by the AGC ?
Is it possible that the calculation of the parameters became out of limit and the picture is taken with default or uncontrolled parameters ?

Thanks a lot

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 9254
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: RaspYUV auto exposure (-ex night) extended

Sat Jun 27, 2015 9:21 pm

Yes, you've found the right code.
167/1000 = 0.167, or approx 1/6 frames/sec = 6 secs/frame. That is the highest we have longest exposure we managed to get from this sensor. I would expect you to need to set it on both preview and stills ports to get sensible values.

AGC will take typically 20-40 frames to stabilise. If you're only running at a max of 1fps, then that is at least 20 secs. Sorry, that is a trade off that has to be made. Most of the AGC calcs are performed during preview. It will recalculate on capture, but won't make a significant change in this case as preview and capture have the same time constraints.

To be honest you are pushing the tested behaviour here, so I can't say for certain what will happen in various situations. If given enough time, I would expect the AGC algo to settle on similar values. You may get better results if you increase the delay even further.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

muth
Posts: 27
Joined: Sun Aug 05, 2012 3:32 pm

Re: RaspYUV auto exposure (-ex night) extended

Sun Jun 28, 2015 11:58 am

Thank you very much for these explanations! I'm really happy to have such fast and precise support.
You are right, I see now it is pushing beyond normal uses of the software. I'll continue to play a bit with the FPS parameters and let you know if I get more stable results.
Thanks again and have a nice Sunday!

muth
Posts: 27
Joined: Sun Aug 05, 2012 3:32 pm

Re: RaspYUV auto exposure (-ex night) extended

Sun Jun 28, 2015 4:47 pm

Hello again.
I think I pointed something. To be sure of using maximum possibilities I used :

Code: Select all

MMAL_PARAMETER_FPS_RANGE_T fps_range = {{MMAL_PARAMETER_FPS_RANGE, sizeof(fps_range)},{1, 6}, {6, 1}};
mmal_port_parameter_set(preview_port, &fps_range.hdr);
...
mmal_port_parameter_set(still_port, &fps_range.hdr);
a range between 6 fps to 6 seconds exposition.

I made the previous tests with native resolution. And there is a 'hot' corner on my CCD. Probably confusing the AGC. I tried with a partial FOV (1920x1088) and a got nice picture with 3.2 seconds shutter speed at ISO400 ! I can probably get more by changing the metering method to avoid hot pixels, which are now visible at such long exposition time.

Many thanks for the support !

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 9254
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: RaspYUV auto exposure (-ex night) extended

Sun Jun 28, 2015 5:44 pm

You won't manage to get such a wide range of frame rates. There are 2 main modes you are switching between - one does 1-15fps, and the other 0.1666-1fps. It will not dynamically switch between the two.

If you're doing long exposures, have you disabled the LED on the camera board? It can have a significant impact on the images if not, and show up as a hot red corner.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

muth
Posts: 27
Joined: Sun Aug 05, 2012 3:32 pm

Re: RaspYUV auto exposure (-ex night) extended

Sun Jun 28, 2015 6:25 pm

Understood, you're right the fps stay in one of the mode.
I'll probably stay with 0.1666-1fps, even if it is slower to adapt.
Yes, I disabled the red led (in fact I removed it). I figured it out before and I though it was why AGC not use long exposure.

Return to “Camera board”