Fer
Posts: 35
Joined: Tue Feb 21, 2017 10:27 am

Combining (captured) images with mmal?

Tue Feb 21, 2017 11:22 am

Hello,
I'm using raspistill with a Pi 3 and a camera module v1.
I'd like cleaner images (less shadow noise); I already exploited the 2x2 pixel binning mode.
I'm now looking into image averaging (multisampling): say I take 4 identical pictures (of a static object of course) and average them into 1 resulting image.
Is there a way to accomplish this using mmal? Can someone point me in the right direction?

Thank you

Fernando

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 28358
Joined: Sat Jul 30, 2011 7:41 pm

Re: Combining (captured) images with mmal?

Tue Feb 21, 2017 12:36 pm

Fer wrote:Hello,
I'm using raspistill with a Pi 3 and a camera module v1.
I'd like cleaner images (less shadow noise); I already exploited the 2x2 pixel binning mode.
I'm now looking into image averaging (multisampling): say I take 4 identical pictures (of a static object of course) and average them into 1 resulting image.
Is there a way to accomplish this using mmal? Can someone point me in the right direction?

Thank you

Fernando
No way in MMAL, you will need to use some stacking software on the ARM. Not difficult, and if you use all four cores, will be pretty quick. NEON code would be even faster - might be some code already out there to do that.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

Fer
Posts: 35
Joined: Tue Feb 21, 2017 10:27 am

Re: Combining (captured) images with mmal?

Tue Feb 21, 2017 1:24 pm

Thank you.

One option would be saving 4 files in raw+jpg, extracting the raw part externally, averaging and converting to jpeg, but seems quite inefficient: I'd prefer to modify raspistill source and operate "internally", so to speak.
Do you have any advice?
Raspistill iterates over data buffers from the camera component and passes them to the encoder component, which then saves to file:

Code: Select all

// Enable the encoder output port and tell it its callback function
status = mmal_port_enable(encoder_output_port, encoder_buffer_callback);

// Send all the buffers to the encoder output port
num = mmal_queue_length(state.encoder_pool->queue);
for (q=0;q<num;q++)
{
    MMAL_BUFFER_HEADER_T *buffer = mmal_queue_get(state.encoder_pool->queue);

    if (!buffer)
        vcos_log_error("Unable to get a required buffer %d from pool queue", q);

    if (mmal_port_send_buffer(encoder_output_port, buffer)!= MMAL_SUCCESS)
        vcos_log_error("Unable to send a buffer to encoder output port (%d)", q);
}
I can't figure how to access the whole (raw) frame. :|

Thanks for reading!

Fernando

AndyPi
Posts: 83
Joined: Wed Feb 22, 2012 10:24 pm
Location: Gloucestershire,UK

Re: Combining (captured) images with mmal?

Tue Feb 21, 2017 1:31 pm

Its possible I think to convert images in to GL textures which can then be processed with shaders.

Code: Select all

            egl_image = eglCreateImageKHR(eglFS->display,
                                       EGL_NO_CONTEXT,
                                       EGL_IMAGE_BRCM_MULTIMEDIA_Y,
                                       (EGLClientBuffer)buf->data,
                                       NULL);

            if (egl_image == EGL_NO_IMAGE_KHR) Error("No egl image created",0);

            glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, egl_image);

ethanol100
Posts: 663
Joined: Wed Oct 02, 2013 12:28 pm

Re: Combining (captured) images with mmal?

Tue Feb 21, 2017 1:38 pm

Another way would be to handle your buffers on your own. You can receive 4 frames from the camera's still port. Average them and send the averaged buffer to the JPEG encoder.

Fer
Posts: 35
Joined: Tue Feb 21, 2017 10:27 am

Re: Combining (captured) images with mmal?

Tue Feb 21, 2017 2:02 pm

ethanol100 wrote:Another way would be to handle your buffers on your own. You can receive 4 frames from the camera's still port. Average them and send the averaged buffer to the JPEG encoder.
Well, yes, that was the idea: the problem is, I can't find a way to get the whole frame from the still port. :|

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

Re: Combining (captured) images with mmal?

Tue Feb 21, 2017 2:17 pm

Fer wrote:
ethanol100 wrote:Another way would be to handle your buffers on your own. You can receive 4 frames from the camera's still port. Average them and send the averaged buffer to the JPEG encoder.
Well, yes, that was the idea: the problem is, I can't find a way to get the whole frame from the still port. :|
Look at RaspiStillYuv instead of RaspiStill.
https://github.com/raspberrypi/userland ... StillYUV.c

And you'll need to think about gpu_mem settings - each 5MPix frame will be 7.5MB as YUV420, or 10MB as YUV422.
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.

Fer
Posts: 35
Joined: Tue Feb 21, 2017 10:27 am

Re: Combining (captured) images with mmal?

Tue Feb 21, 2017 2:20 pm

Thanks for the tip!

Fernando

Return to “Camera board”