cancel
Showing results for 
Search instead for 
Did you mean: 

How to implement an algoritm for image processing

BTurc.2
Senior

Hi there!

I'm using an STM32F746 disco with an OV9655 camera module. I have already configured all necessary peripherals: LTDC, FMC and DCMI.

What I want to do exactly is tell the camera in which buffer I want it to save the image. In the meantime, process the previous image using the CPU. When I finished processing the image, I want to tell the LCD to display it.

Maybe it will better br understood if you see this:

 while (1)

 {

// HAL_Delay(500);

 //DCMI->CR |= (1U << 0);

 switch (sequence) {

case SEQ_1:

/* 1- Capture -> Buff_1 */

Take_a_frame( buff_address[0] );

sequence = SEQ_2;

break;

case SEQ_2:

/* 1- Capture -> Buff_2 2- Pocess Buff_1 */

Take_a_frame( buff_address[1] );

processar( );

sequence = SEQ_3;

break;

case SEQ_3:

/* 1- Capture -> Buff_3 2- Process Buff_2 3- Buff_1 -> LCD */

Take_a_frame( buff_address[2] );

processar( );

Show_frame( buff_address[0] );

sequence = SEQ_4;

break;

case SEQ_4:

/* 1- Capture -> Buff_1 2- Process Buff_3 3- Buff_2 -> LCD */

Take_a_frame( buff_address[0] );

processar( 2 );

Show_frame( buff_address[1] );

sequence = SEQ_5;

break;

case SEQ_5:

/* 1- Capture -> Buff_2 2- Process Buff_1 3- Buff_3 -> LCD */

Take_a_frame( buff_address[1] );

processar( );

Show_frame( buff_address[2] );

sequence = SEQ_3;

break;

default:

break;

}

 }

I have tried to configure the camera in different ways: Snapshot mode, continuous mode, whith the DMA in circular of normal mode... But it gives me a lot of problems.

Could someone tell me if I'm doing the right thing when using 3 buffers? How should the camera be configured? (shapshot or continuous) How should the DMA be configured? (normal or sircular). What would be a more efficient way to do it?

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Jayden Cai
Associate II

Configure the camera to capture images and transfer them to memory. This can be done in either snapshot or continuous mode depending on your application requirements.

Set up the DMA controller to transfer the image data from the camera to a buffer in memory. You can use either circular or normal mode depending on your requirements. Circular mode enables continuous data transfer without interruption, while normal mode is suitable for capturing a limited number of frames.

Once an image has been captured and transferred to memory, begin processing it using the CPU. This can include operations such as filtering, edge detection, or object recognition.

After processing is complete, send the processed image data to the LCD for display. This can be done by configuring the LTDC peripheral to output the image data to the display.

Repeat the process for the next image by setting up the camera and DMA to capture another frame into a new buffer.

Using multiple buffers as you are currently doing is a good way to ensure that there is always an available buffer for capturing new images while processing takes place on previous images. The specific number of buffers required will depend on the processing time and the rate at which new images need to be captured.

Overall, the key to efficient image processing is to balance the speed of the hardware with the complexity of the algorithms being used. You may need to experiment with different configurations to find the optimal setup for your particular application.

View solution in original post

4 REPLIES 4
Jayden Cai
Associate II

Configure the camera to capture images and transfer them to memory. This can be done in either snapshot or continuous mode depending on your application requirements.

Set up the DMA controller to transfer the image data from the camera to a buffer in memory. You can use either circular or normal mode depending on your requirements. Circular mode enables continuous data transfer without interruption, while normal mode is suitable for capturing a limited number of frames.

Once an image has been captured and transferred to memory, begin processing it using the CPU. This can include operations such as filtering, edge detection, or object recognition.

After processing is complete, send the processed image data to the LCD for display. This can be done by configuring the LTDC peripheral to output the image data to the display.

Repeat the process for the next image by setting up the camera and DMA to capture another frame into a new buffer.

Using multiple buffers as you are currently doing is a good way to ensure that there is always an available buffer for capturing new images while processing takes place on previous images. The specific number of buffers required will depend on the processing time and the rate at which new images need to be captured.

Overall, the key to efficient image processing is to balance the speed of the hardware with the complexity of the algorithms being used. You may need to experiment with different configurations to find the optimal setup for your particular application.

KDJEM.1
ST Employee

Hello @BTurc.2​ ;

Besides, the reply shared by @jayden cai​  I advise you to refer to “ Introduction to digital camera interface (DCMI) for STM32 MCUs - Application note�? and to "LCD-TFT display controller (LTDC) on STM32 MCUs - Application note", that may help you.

Kaouthar

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Thank Jayden Cai,

I have set the camera in snapshot mode, to have images every time you enable it in the DCMI->CR register. The DMA is configured in circular mode and I indicate where I wnat to store the frame with the next function: HAL_DCMI_Start_DMA(handle_dcmi, DCMI_MODE_SNAPSHOT, frame_buffer, IMAGE_SIZE);

When I try to store the frame in the first buffer works fine but, whe I use the same function but with a second buffer it don't work, the LCD shows a noise screen when I tell It to show the second buffer.

How do I save successively in the 2 buffers?

Jayden Cai
Associate II

One approach you could take is to use a double buffer technique, where you have two buffers that alternate between being used for image capture and processing/display.