Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.
Merged
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
06157b7
Fix typo in DCP tutorial
sebromero Oct 14, 2020
327b6dc
Add scaffold for face detection tutorial
sebromero Oct 14, 2020
9877cb5
Added What You Will Learn
Lenardgeorge Oct 15, 2020
90c710f
Added Introduction
Lenardgeorge Oct 15, 2020
9f38005
Added Explaination for HAAR Cascade
Lenardgeorge Oct 15, 2020
17a4e08
Added Image for Explaination
Lenardgeorge Oct 15, 2020
0509f34
Added Cover Image
Lenardgeorge Oct 15, 2020
f77a3df
Updated the Step-by-Steps
Lenardgeorge Oct 15, 2020
a9010ad
Add first version of the complete script
sebromero Oct 15, 2020
fd78173
Update example code with image overlay
sebromero Oct 15, 2020
887701b
Changed the Steps
Lenardgeorge Oct 15, 2020
6e61e17
Added 3-loading-haar-cascade
Lenardgeorge Oct 15, 2020
a99f865
Added 4-reading-bitmap-image
Lenardgeorge Oct 15, 2020
c378e79
Added 5-finding-face-features
Lenardgeorge Oct 15, 2020
944abff
Merge branch 'face-detection-tutorial' of https://github.com/bcmi-lab…
Lenardgeorge Oct 15, 2020
8931a08
Updated Step-by-Steps
Lenardgeorge Oct 15, 2020
1e7e68f
Add task assignment
sebromero Oct 15, 2020
8b67ef5
Refactor the example code for better understandability
sebromero Oct 15, 2020
408667c
Add more info to the introduction
sebromero Oct 15, 2020
33c7f25
Add descriptions to the module imports
sebromero Oct 15, 2020
79b0611
Update the example code with refactorings
sebromero Oct 15, 2020
e1f0c94
Re-work the ‘Displaying a Bitmap Image’ section
sebromero Oct 15, 2020
99dff14
Add conclusion section
sebromero Oct 15, 2020
57a3b7f
Rephrase pbm format explanation
sebromero Oct 15, 2020
fe51096
Added Example Sketch Image
Lenardgeorge Oct 15, 2020
129ef00
Updated Introduction
Lenardgeorge Oct 15, 2020
af725c9
Updated HaarCascade-Explaination
Lenardgeorge Oct 15, 2020
65809d2
Added 01-Basic-Setup
Lenardgeorge Oct 15, 2020
09702de
Added 02-fd-Sketch
Lenardgeorge Oct 15, 2020
a18407b
added 03-Preparing-the-Script
Lenardgeorge Oct 15, 2020
ec7f0b6
Added 03-Preparing-the-Sensor
Lenardgeorge Oct 15, 2020
e9c34a9
Added Preparing the Sensor
Lenardgeorge Oct 15, 2020
8df640a
Added Preparing-the-sensor-code
Lenardgeorge Oct 15, 2020
ffc75eb
Updated 07-Uploading-The-Script
Lenardgeorge Oct 15, 2020
eb031d2
Added Next-Steps
Lenardgeorge Oct 15, 2020
c97b426
Re-structure sections
sebromero Oct 16, 2020
b171819
Fix typos and phrasing
sebromero Oct 16, 2020
ae290e3
Added Images to the Content
Lenardgeorge Oct 16, 2020
2e5f69d
Updated Cover Image
Lenardgeorge Oct 16, 2020
323a381
Add smiley image
sebromero Oct 16, 2020
e364106
Rephrase sentences
sebromero Oct 16, 2020
48d790b
Replace output image
sebromero Oct 16, 2020
78b187b
Rephrase sentences
sebromero Oct 16, 2020
3a4de36
Remove unused image
sebromero Oct 16, 2020
eb83586
Fix spelling of Haar
sebromero Oct 16, 2020
8cafda4
Add meta data for Face detection tutorial
sebromero Oct 16, 2020
bf85f83
Spell checking fixes
sebromero Oct 16, 2020
8c67cd8
Change title
sebromero Oct 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Re-structure sections
  • Loading branch information
sebromero committed Oct 16, 2020
commit c97b4267f665a8aaed01330611bbff35d622fefc
21 changes: 9 additions & 12 deletions content/tutorials/portenta-h7/por-openmv-fd/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ In this tutorial you will build a MicroPython application with OpenMV that uses
- Portenta Bootloader Version 20+
- OpenMV IDE 2.6.4+

# Face Detection through HAAR Cascade.
# The HAAR Cascade Algorithm

Face detection happens by using a machine learning based approach called HAAR cascade. 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 contains 25 such stages. HAAR Cascades are trained against hundreds of images with a face that are labelled as faces and an equivalent amount of images that dont have faces in them labeled differently.

![The HAAR Cascade Process](assets/por_openmv_haar_cascade.svg)

## 1. The Basic Setup
# Creating the Face Detection Script

For this tutorial you will be using the OpenMV IDE along with the OpenMV firmare on your Portenta H7 to build the face detection sketch. 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://www.arduino.cc/pro/tutorials/portenta-h7/por-openmv-bt) to configure the development environment.

## 2. The face_detection.py Sketch
## 1. The Basic Setup

Attach your Vision Carrier to your Portenta H7 and open the **openMV** Editor. For this tutorial, you will be using **face_detection.py** example provided by OpenMV as a starting point. This example can be found inside **File->Examples->Face-Detection->face_detection.py**.
Attach your Vision Carrier to your Portenta H7 and open the **OpenMV** Editor. For this tutorial, you will be using **face_detection.py** example provided by OpenMV as a starting point. This example can be found inside **File->Examples->Face-Detection->face_detection.py**.

![The face_detection.py example sketch](assets/por_openmv_fd_example.png)

You will also have to download a bitmap file (.pbm format) of your favourite emoji and Store it on the microSD card. Insert the microSD card into the Vision Carrier's SD card slot and connect the board to your computer.

## 2. Preparing the Script
## 2. Importing the Modules

The Script starts by importing the `pyb`, `sensor`, `image` and `time` modules for handling the board functions, camera sensor settings, machine vision algorithms and time tracking methods.
The script starts by importing the `sensor`, `image` and `time` modules for handling the camera sensor, using machine vision algorithms and time tracking functions.

```py
import sensor # Import the module for sensor related functions
Expand All @@ -55,17 +55,15 @@ sensor.set_framesize(sensor.HQVGA)
sensor.set_pixformat(sensor.GRAYSCALE)
```

## 4. Finding the Face Features

OpenMV provides a packaged Haar Cascade class formatted for the Vision Shield's Camera. The [`image.HaarCascade(path, number of stages)`](https://docs.openmv.io/library/omv.image.html#class-haarcascade-feature-descriptor) is used to load the built in HaarCascade binary file into the memory using the [`image`](https://docs.openmv.io/library/omv.image.html#) module. The `path` helps to specify the type of Haar Cascade file thats required which in this case is of the type `frontalface`. The `number of stages`is use to specify the Haar Cascade Stages required.

```python
face_cascade = image.HaarCascade("frontalface", stages=25)
print(face_cascade)
```

## 4. Finding the Face Features

https://openmv-doc.readthedocs.io/library/omv.image.html#image.image.find_features

## 5. Displaying a Bitmap Image

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.
Expand Down Expand Up @@ -107,9 +105,8 @@ import image # Import module containing machine vision algorithms
import time # Import module for tracking elapsed time

sensor.reset() # Resets the sensor

sensor.set_contrast(3) # Sets the contrast to the highest level (min -3, max 3)
sensor.set_gainceiling(16)
sensor.set_gainceiling(16) # Sets the amplification of camera sensor signal

# HQVGA and GRAYSCALE are the best for face tracking.
sensor.set_framesize(sensor.HQVGA)
Expand Down