You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document is a quick guide that introduces ***STM32 Image Processing Library*** and provides advises about the preparation and the usage of the *STM32 Image Processing Library* in real applications.
9
+
This document is a quick guide that introduces ***STM32 Image Processing Library*** and provides advise about the preparation and the usage of the *STM32 Image Processing Library* in real applications.
10
10
11
11
*STM32 Image Processing Library* (in short, ***STM32IPL***) is a C software library for ***STMicroelectronics STM32 MCUs*** that provides specific functionalities that help the development of visual analysis applications.
12
12
@@ -21,7 +21,7 @@ Please, note that this document does not contain detailed specifications of the
21
21
22
22
## Main characteristics
23
23
24
-
*STM32IPL* is an opensource software library, written in C, that offers image processing and computer vision functionalities for a faster development of visual analysis applications on ***STM32*** microcontrollers.
24
+
*STM32IPL* is an open-source software library, written in C, that offers image processing and computer vision functionalities for a faster development of visual analysis applications on ***STM32*** microcontrollers.
25
25
26
26
The main key characteristics of *STM32IPL* are:
27
27
@@ -63,9 +63,9 @@ The software architecture of a typical *STM32* application exploiting *STM32IPL*
63
63
64
64
*STM32IPL* is released as open source ***STM32Cube Middleware*** component; basically, all the *STM32IPL* functions are platform independent, with few exceptions:
65
65
66
-
- The I/O functions that perform reading/writing operation on files, in particular, the two read/write functions that handle the supported image file formats as *BMP* (*Windows Bitmap*), *PPM* (*Portable PixMap*), *PGM* (*Portable GreyMap*), and *JPEG*: these functions depend on the following thirdparty open source libraries that are part of the set of *STM32Cube Middleware* components:
66
+
- The I/O functions that perform reading/writing operation on files, in particular, the two read/write functions that handle the supported image file formats as *BMP* (*Windows Bitmap*), *PPM* (*Portable PixMap*), *PGM* (*Portable GreyMap*), and *JPEG*: these functions depend on the following third-party open source libraries that are part of the set of *STM32Cube Middleware* components:
67
67
68
-
-***FatFs***, that offers read/write operations on a *FatFS* file system (which can be, for example, mounted on an SD card)
68
+
-***FatFs***, that offers read/write operations on a *FatFS* file system (which can be, for example, mounted on an microSD card)
69
69
70
70
-***LibJPEG***, that offers *JPEG* encoding and decoding functionalities
71
71
@@ -83,7 +83,7 @@ This section describes the basic steps needed to develop an *STM32* application
83
83
84
84
### Setting the project properties
85
85
86
-
First of all, it is necessary to add the *STM32_ImageProcessing_Library/Inc* folder to the list of the include directories of the application project.
86
+
As first step, it is necessary to add the *STM32_ImageProcessing_Library/Inc* folder to the list of the include directories of the application project.
87
87
88
88
Then, it is necessary to add `STM32IPL` to the list of define symbols of the compiler pre-processor.
89
89
@@ -226,18 +226,25 @@ So, in general, it is up to the developer to read the documentation to understan
226
226
227
227
As soon as the *STM32IPL* is not needed anymore, the user can call `STM32Ipl_DeInitLib()` to release the whole memory block reserved at the beginning, so that it can be made available for further usages.
228
228
229
-
##Example
229
+
### Containers
230
230
231
-
This section shows a simple example that uses *STM32IPL* to:
231
+
*STM32IPL* uses two types of containers to store complex data: **list** and **array**. These containers are used as arguments to some *STM32IPL* functions, sometimes as input and sometimes as output parameters. In the following *Examples* section some handy examples that explain how to use such containers are reported.
232
+
233
+
## Examples
234
+
235
+
This section shows simple practical examples explaining how to use *STM32IPL* to develop applications. Such examples assume that *STM32IPL* has been properly initialized as explained in the section *Initialization of the library* above.
236
+
237
+
The examples below typically read image from files, so it is assumed that the user has properly initialized and mounted the *FatFs* file system, for instance on a microSD card, as the pertinent source code is not included here.
238
+
239
+
### Resize
240
+
241
+
This example explains how to:
232
242
233
243
- read an image
234
-
- resize it to a destination image
244
+
- resize it to a smaller destination image
235
245
- show both images to the screen
236
246
237
247
```c
238
-
/*
239
-
* This example shows how to resize a source image to a smaller destination image.
240
-
*/
241
248
voidResize(void)
242
249
{
243
250
image_t srcImg; // Source image.
@@ -252,7 +259,8 @@ void Resize(void)
252
259
253
260
// Allocate memory to the destination image.
254
261
// The destination image must have the same format as the source image.
255
-
if (stm32ipl_err_Ok == STM32Ipl_AllocData(&dstImg, dstWidth, dstHeight, image_bpp_t)srcImg.bpp)) {
262
+
if (stm32ipl_err_Ok == STM32Ipl_AllocData(&dstImg, dstWidth, dstHeight,
263
+
image_bpp_t)srcImg.bpp)) {
256
264
// Resize the source image and store the results into the destination image.
257
265
if (stm32ipl_err_Ok == STM32Ipl_Resize(&srcImg, &dstImg, NULL)) {
258
266
// Display the destination image on the screen (right side).
@@ -269,3 +277,187 @@ void Resize(void)
269
277
}
270
278
```
271
279
280
+
### Face Detection
281
+
282
+
This example explains how to:
283
+
284
+
- read an image
285
+
- detect the faces in the image
286
+
- use an array container to get the results (detected faces)
287
+
- draw the bounding boxes of the faces in the image
288
+
- show the image with the bounding boxes of the detected faces on the screen
289
+
290
+
```c
291
+
void FaceDetection(void)
292
+
{
293
+
image_t img;
294
+
cascade_t cascade; // The cascade structure used by the object detector.
295
+
uint16_t thickness = 2; // Set the thickness of the rectangle (pixels).
296
+
bool fill = false; // Avoid to fill the rectangle.
297
+
float scaleFactor = 1.25f; // Modify this value to detect objects at
298
+
// different scale (must be > 1.0f).
299
+
float threshold = 0.75f; // Modify this value to tune the detection rate against
300
+
// the false positive rate (0.0f - 1.0f).
301
+
302
+
// Load face cascade.
303
+
if (stm32ipl_err_Ok == STM32Ipl_LoadFaceCascade(&cascade)) {
304
+
// Load an image from file system.
305
+
if (stm32ipl_err_Ok == STM32Ipl_ReadImage(&img, "myImage.bmp")) {
306
+
uint32_t faceCount;
307
+
array_t *faces = 0;
308
+
309
+
// Detect faces. No ROI is passed, so the full image is analyzed.
310
+
if (stm32ipl_err_Ok == STM32Ipl_DetectObject(&img, &faces, NULL, &cascade,
311
+
scaleFactor, threshold)) {
312
+
313
+
// Get the number of detected faces.
314
+
faceCount = array_length(faces);
315
+
316
+
// Get the bounding box for each detected face.
317
+
for (int i = 0; i < faceCount; i++) {
318
+
rectangle_t *r = array_at(faces, i);
319
+
320
+
// Draw the bounding box around each detected face.
0 commit comments