Skip to content

Commit 30ccd93

Browse files
authored
Merge pull request #491 from arduino/martab1994-patch-6
Update content.md
2 parents 3f7608a + 8536f38 commit 30ccd93

File tree

1 file changed

+17
-17
lines changed
  • content/hardware/04.pro/shields/portenta-vision-shield/tutorials/creating-basic-face-filter

1 file changed

+17
-17
lines changed

content/hardware/04.pro/shields/portenta-vision-shield/tutorials/creating-basic-face-filter/content.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Creating a Basic Face Filter With OpenMV
33
coverImage: assets/por_openmv_fd_cover.svg
44
difficulty: intermediate
55
tags: [OpenMV, Face Detection, Haar Cascade, Machine Vision, Machine Learning]
6-
description: In this tutorial you will build a MicroPython application with OpenMV that uses the Portenta Vision Shield to detect faces and overlay them with a custom bitmap image.
6+
description: In this tutorial you will build a MicroPython application with OpenMV, to use the Portenta Vision Shield to detect faces and overlay them with a custom bitmap image.
77
author: Sebastian Romero, Lenard George
88
hardware:
99
- hardware/04.pro/boards/portenta-h7
@@ -13,7 +13,7 @@ software:
1313
---
1414

1515
## Overview
16-
In this tutorial you will build a MicroPython application with OpenMV that uses the Portenta Vision Shield to detect faces and overlay them with a custom bitmap image. Think of it as building your own camera filter that puts a smile on every face it detects. This tutorial is based on the face detection example that comes with the OpenMV IDE.
16+
In this tutorial you will build a MicroPython application with OpenMV, to use the Portenta Vision Shield to detect faces and overlay them with a custom bitmap image. Think of it as building your own camera filter that puts a smile on every face it detects. This tutorial is based on the face detection example that comes with the OpenMV IDE.
1717

1818
## Goals
1919

@@ -33,23 +33,23 @@ In this tutorial you will build a MicroPython application with OpenMV that uses
3333

3434
## The Haar Cascade Algorithm
3535

36-
By harnessing the power of machine vision algorithms objects can be detected in a camera stream. Those algorithms can be trained to detect the desired type of object. In this tutorial you will use a machine learning based approach called Haar Cascade to detect faces.
36+
By harnessing the power of machine vision algorithms, objects can be detected in a camera stream. Those algorithms can be trained to detect the desired type of object. In this tutorial, you will use a machine learning based approach called Haar Cascade to detect faces.
3737

3838
![The Haar Cascade process for detecting faces](assets/por_openmv_haar_cascade.svg)
3939

40-
This approach uses a cascade algorithm that has multiple stages where the output from one stage acts as additional information for the next stage in the cascade. The different stages are responsible for detecting edges, lines, contrast checks and calculating pixel values in a given image. Larger areas of the image are checked first in the earlier stages followed by more numerous and smaller area checks in later stages. The Haar Cascade function provided by OpenMV allows to specify the amount of stages. Fewer stages make the detection faster while leading to more false positives.
40+
This approach uses a cascade algorithm that has multiple stages, where the output from one stage acts as additional information for the next stage in the cascade. The different stages are responsible for detecting edges, lines, contrast checks and calculating pixel values in a given image. Larger areas of the image are checked first in the earlier stages, followed by more numerous and smaller area checks in later stages. The Haar Cascade function provided by OpenMV allows to specify the amount of stages. Fewer stages make the detection faster, while leading to more false positives.
4141

42-
The built-in Haar Cascade model for faces was trained with hundreds of images containing faces that are labeled as such and images that don't contain faces labeled differently. That allows the algorithm to distinguish such images after it is being trained.
42+
The built-in Haar Cascade model for faces was trained with hundreds of images containing faces that are labeled as such and images that do not contain faces labeled differently. That allows the algorithm to distinguish such images after it is being trained.
4343

4444
## Instructions
4545

4646
### Creating the Face Detection Script
4747

48-
For this tutorial you will be using the OpenMV IDE along with the OpenMV firmware on your Portenta H7 to build the face detection script. If this is your first time using the Vision Carrier and OpenMV we recommend you to take a look at the "Configuring the Development Environment" section inside the [Blob Detection tutorial](https://docs.arduino.cc/tutorials/portenta-vision-shield/blob-detection) to configure the development environment.
48+
For this tutorial, you will be using the OpenMV IDE along with the OpenMV firmware on your Portenta H7 to build the face detection script. If this is your first time using the Portenta Vision Shield and OpenMV, we recommend you to take a look at the "Configuring the Development Environment" section inside the [Blob Detection tutorial](https://docs.arduino.cc/tutorials/portenta-vision-shield/blob-detection) to configure the development environment.
4949

5050
### 1. The Basic Setup
5151

52-
Attach your Vision Carrier to your Portenta H7 and open the **OpenMV** Editor. For this tutorial, you will create a new script that is based on the face detection example provided by OpenMV. Create a new script by clicking the "New File" button in the toolbar on the left side and save it as **face_detection.py**.
52+
Attach your Portenta Vision Shield to your Portenta H7 and open the **OpenMV** Editor. For this tutorial, you will create a new script that is based on the face detection example provided by OpenMV. Create a new script by clicking the "New File" button in the toolbar on the left side and save it as **face_detection.py**.
5353

5454
### 2. Importing the Modules
5555

@@ -63,7 +63,7 @@ import time # Import module for tracking elapsed time
6363

6464
### 3. Preparing the Sensor
6565

66-
The next step is to calibrate the camera sensor for achieving the best results using the `sensor` module. You can use the `set_contrast()` function to set the contrast of the sensor to its highest value (3). This can help the algorithm identifying lines and edges more easily. `set_gainceiling()` controls the amplification of the signal from the camera sensor including any associated background noise. For maximizing the detection success rate it is recommended to set the camera frame size to `HQVGA`.
66+
The next step is to calibrate the camera sensor to achieve the best results using the `sensor` module. You can use the `set_contrast()` function to set the contrast of the sensor to its highest value (3). This can help the algorithm identifying lines and edges more easily. `set_gainceiling()` controls the amplification of the signal from the camera sensor including any associated background noise. For maximizing the detection success rate, it is recommended to set the camera frame size to `HQVGA`.
6767

6868
```python
6969
# Sensor settings
@@ -75,7 +75,7 @@ sensor.set_pixformat(sensor.GRAYSCALE)
7575

7676
### 4. Finding the Face Features
7777

78-
OpenMV provides a Haar Cascade class ready to be used with the Vision Shield's camera. The function [`image.HaarCascade(path, number of stages)`](https://docs.openmv.io/library/omv.image.html#class-Haarcascade-feature-descriptor) is used to load a Haar Cascade model into memory. The `path` parameter can be used to either specify the location of a custom Haar Cascade model or to use the built-in `frontalface` model. The `stages` parameter is use to specify the desired Haar Cascade stages.
78+
OpenMV provides a Haar Cascade class ready to be used with the Portenta Vision Shield's camera. The function [`image.HaarCascade(path, number of stages)`](https://docs.openmv.io/library/omv.image.html#class-Haarcascade-feature-descriptor) is used to load a Haar Cascade model into memory. The `path` parameter can be used to either specify the location of a custom Haar Cascade model or to use the built-in `frontalface` model. The `stages` parameter is use to specify the desired Haar Cascade stages.
7979

8080
***Remember: Fewer stages make the detection faster while leading to more false positives.***
8181

@@ -86,19 +86,19 @@ print(face_cascade) # Prints the Haar Cascade configuration
8686

8787
### 5. Displaying a Bitmap Image
8888

89-
Once you know the location of the faces in the camera image you can overlay them with an image of your choice. OpenMV currently supports bmp, pgm or ppm image formats. Image formats with an alpha layer such as PNG are not supported yet.
89+
Once you know the location of the faces in the camera image, you can overlay them with an image of your choice. OpenMV currently supports bmp, pgm or ppm image formats. Image formats with an alpha layer such as PNG are not supported yet.
9090

91-
In this tutorial you will use a preloaded smiley image in the monochrome [Portable Bitmap Image](https://en.wikipedia.org/wiki/Netpbm) (.pbm) format. This format consists of a matrix of zeroes and ones denoting black and white pixels. 1 stands for a black pixel, 0 for a white one. If you want to create your custom image make sure you save it in one of the supported bitmap formats (bmp, pgm or ppm). You may use an image editor of your choice which supports exporting images in one of these formats. For this tutorial Adobe Photoshop was used.
91+
In this tutorial you will use a preloaded smiley image in the monochrome [Portable Bitmap Image](https://en.wikipedia.org/wiki/Netpbm) (.pbm) format. This format consists of a matrix of zeroes and ones denoting black and white pixels. 1 stands for a black pixel, 0 for a white one. If you want to create your custom image, make sure you save it in one of the supported bitmap formats (bmp, pgm or ppm). You may use an image editor of your choice which supports exporting images in one of these formats. For this tutorial Adobe Photoshop was used.
9292

93-
Connect your Portenta board to your computer if you haven't done so. Make sure you are running the OpenMV firmware on the Portenta. If you haven't installed the OpenMV firmware yet take a look at the "Configuring the Development Environment" section which explains how to proceed in that case.
93+
Connect your Portenta board to your computer if you have not done so yet. Make sure you are running the OpenMV firmware on the Portenta. If you have not installed the OpenMV firmware yet, take a look at the "Configuring the Development Environment" section which explains how to proceed in that case.
9494

9595
Download [this file](assets/face.pbm) containing the smiley bitmap and copy it to the Flash drive that was mounted when you connected the Portenta running the OpenMV firmware.
9696

97-
***The on-board memory gets mounted as a Flash drive. Therefore this will work even if you haven't inserted an SD card.***
97+
***The on-board memory gets mounted as a Flash drive. Therefore this will work even if you have not inserted an SD card.***
9898

9999
![Copy the bitmap image to the Flash drive](assets/por_openmv_fd_drive.png)
100100

101-
Load the image into a variable called `faceImage` using the `Image()` function from the `image` module. The initial slash refers to the root directory of the Flash drive. In order to use the image as an overlay to the camera stream instead of directly displaying it set the `copy_to_fb` to False such that it doesn't get copied into the frame buffer automatically.
101+
Load the image into a variable called `faceImage` using the `Image()` function from the `image` module. The initial slash refers to the root directory of the Flash drive. In order to use the image as an overlay to the camera stream, instead of directly displaying it, set the `copy_to_fb` to False such that it does not get copied into the frame buffer automatically.
102102

103103
```python
104104
faceImage = image.Image("/face.pbm", copy_to_fb=False)
@@ -172,13 +172,13 @@ while (True):
172172
print(clock.fps())
173173
```
174174

175-
Click on the "Play" button at the bottom of the left toolbar. Point the camera on the Vision Shield towards your face check if the Portenta can detect it. Once it detects your face it should be covered with a smiley.
175+
Click on the "Play" button at the bottom of the left toolbar. Point the camera on the Vision Shield towards your face and check if the Portenta can detect it. Once it detects your face, it should be covered with a smiley.
176176

177177
![Copy the bitmap image to Flash drive](assets/por_openmv_fd_output.png)
178178

179179
## Conclusion
180180

181-
In this tutorial you learned how to use OpenMV's built-in face detection algorithm which is based on Haar Cascade. Furthermore you learned how to copy a file to the internal flash and how to load an image from the Flash into the memory. You have also learned how to draw an image on top of a snapshot from the camera stream.
181+
In this tutorial you learned how to use OpenMV's built-in face detection algorithm which is based on Haar Cascade. Furthermore, you learned how to copy a file to the internal flash and how to load an image from the Flash into the memory. You have also learned how to draw an image on top of a snapshot from the camera stream.
182182

183183
### Next Steps
184184
The [HaarCascade](https://docs.openmv.io/library/omv.image.html#class-Haarcascade-feature-descriptor) class provided by OpenMV can also detect other facial features such as eyes. For example you could tweak your **face_detection.py** script to detect your eyes simply by changing the `path` parameter from `frontalface ` to `eye` which is also a built-in model. Go ahead and replace the following line in your script and try to figure out how to overlay your eyes with a bitmap image of an eye.
@@ -191,7 +191,7 @@ face_cascade = image.HaarCascade("eye", stages=25)
191191

192192
### Face Detection Issues
193193

194-
- If OpenMV can't detect your face try moving the camera further away or position yourself in front of a wall or another plain background.
194+
- If OpenMV cannot detect your face, try moving the camera further away or position yourself in front of a wall or another plain background.
195195

196196
### Bitmap Loading Issues
197197

0 commit comments

Comments
 (0)