Face Recognition Example
HUSKYLENS 2 face recognition blocks detect, label and count faces, then stream ID, name and position data via I2C or UART. It’s like a smart camera that tags each face with a number plate so Mind+ can check presence, count total faces, and read specific face info for interactive projects.
1.Face Recognition Block
Before You Start:
1.1 Face Recognition and Output Data
Under Face Recognition mode, when a human face appears on the HUSKYLENS 2 display, it can be detected and boxed. We can obtain the relevant data of the human face closest to the cross cursor in the HUSKYLENS 2 display and print this data via UART. The readable face data includes: face ID, face name, width, height, as well as the X and Y coordinates of the face center.
The I2C example program is as follows.
The UART example program is as follows.
The following sample code will only provide code for I2C mode. If you need to use UART mode, simply modify the way HuskyLens is initialized.
In Mind+, click "Upload to Device" and wait for the program to finish uploading. Then, tap the touchscreen to access the Face Recognition feature in HUSKYLENS 2.
Point the HUSKYLENS 2 camera at a face, open the serial port in Mind+, and observe the output.
Result: For unlearned faces, the default output ID is 0.
You can aim the camera at a learned face. For detailed instructions on how to learn a face, please refer to: Face Recognition.
Result: As follows, for a learned face, the output ID will be consistent with the ID displayed on the HUSKYLENS 2 screen.
1.2 Count faces and output the specified face data.
When multiple faces appear in the frame, use the following example program to count the number of faces and obtain relevant data for the face with a specified ID.
The example program is as follows.
Result: As shown in the figure, run the program, and the serial port will print the number of faces in the current image. When a face with ID 1 appears, it will print the relevant data for face ID 1.
Result: As shown in the figure below. When the program runs, if a face with ID 1 is not detected, the serial port will only output the current number of faces.
1.3 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. |
|
Obtain relevant data of the human face nearest to the screen crosshair, including the face's ID, custom face name, center X coordinate, center Y coordinate, width, and height. |
|
Get the total number of faces detected on the screen, including both unregistered and registered faces. |
|
Obtain the relevant data of a specified face when multiple faces appear. |
|
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?
