Face Recognition Example
HuskyLens 2 face recognition with micro:bit lets you detect, count and identify faces, then stream IDs, names and coordinates via serial. It’s like a smart people counter that also tracks eyes, mouth and nose for each selected or closest face.
1. Face Recognition Project Example
Before You Start:
1.1 Recognize Faces and Output Related Data
When face recognition is enabled, faces appearing on the HuskyLens 2 screen will be detected and framed, allowing you to access key data: total detected faces, total trained faces, center-closest face, nth detected face, and specified ID face. This data includes the face’s ID, name, center coordinates (XY), width, and height.
Example program:
Connect to micro:bit and click Download to transfer the program. After successful download, click Show Data to activate data output mode. Align the HuskyLens 2 camera with a face to observe the output.
As shown, when HuskyLens 2 detects two previously trained faces named "JACK" and "TOM", the following data will display:
How to learn faces, please refer to the Face Recognition.
Result:The serial port will output: total detected faces, ID of the center-closest face, name of the first detected face, and total the learned faces.
There are 2 detected faces, so the dot matrix display shows "2".
1.2 Obtaining Facial Feature Data
The system can capture facial feature and positional data for any detected face. Key readable information includes: face ID, name, width, height, center coordinates (X/Y), left/right eye coordinates (X/Y), left/right mouth corner coordinates (X/Y), and nose coordinates (X/Y).
For instance, the sample program below retrieves facial feature data of faces positioned near the camera’s center; this functionality works even for faces not previously learned.
Result: As shown, click "Download" to transfer the program to micro:bit. After successful download, click "Show Device" to activate data output. Align HuskyLens 2 with a face, and the serial port will display the face ID along with coordinates of its key facial features.
1.3 Obtaining Data of a Specific Face
When multiple faces with the same ID appear simultaneously, the program can count their occurrences and retrieve data for the nth face in the detected sequence.
Example program:
Result:As shown, click "Download" to transfer the program. Align HuskyLens 2 with two faces labeled ID 1. After activation, the serial port will output data statistics for these two faces.
1.4 Face Recognition Blocks Description
| block | Description |
|---|---|
|
Used to obtain one set of Face Recognition data under the Face Recognition function of HUSKYLENS 2. |
|
Determine if a human face is present in the current frame. |
|
Retrieves data of the face closest to the screen cross cursor, including face ID, custom face name, center X/Y coordinates, width, height, left/right eye X/Y coordinates, left/right mouth corner X/Y coordinates, and nose X/Y coordinates. |
|
Get the total number of faces detected on the screen, including both unregistered and registered faces. |
|
When multiple faces are detected, retrieves data for a specified face. |
|
Get the total number of learned faces , regardless of whether they appear in the current frame. |
|
Determine if a face with the specified ID exists in the frame. Unlearned IDs are uniformly set to 0, and learned IDs are sorted in the order they were learned. |
|
Gets the total number of detected faces with a specified ID on the screen. |
|
Obtain the number of faces with the specified ID in the current frame. |
|
When multiple faces are detected, retrieve the relevant data of a specified face. |
Was this article helpful?
