Face Recognition Example

HuskyLens 2 face blocks detect, count and label faces; it’s like giving each face a numbered tag so your project can track IDs, positions and learned names in real time.

1.Face Recognition Blocks

Before You Start:

1.1 Face Recognition - Output Relevant Data

Under the face recognition function, when a face appears on the HuskyLens 2 screen, it can be detected and framed, allowing the acquisition of the total number of faces detected and related data for a specified face.

I2C Example Program:

Interface Diagram

UART Example Program:

The sample code provided below is for I2C mode only. If you need to use UART mode, simply modify the code by following the initialization method shown in the program below.

Interface Diagram

Click to upload the program to the device in Mind+, and wait for the upload to complete. Point the HuskyLens 2 camera at the face of the frame to learn it. For detailed instructions on how to learn faces, refer to the Face Recognition. Once the learning is complete, aim at the learned face and observe the output results on the K10 screen.

Output Result: As shown below, you can obtain the total number of faces detected on the screen, whether or not the face has been learned; you can specify the face ID near the center of the camera frame, and the ID of the first detected face (faces not learned will have an ID of 0).

Interface Diagram

1.2 Get Detailed Data of a Specific Face in the Frame

You can obtain the facial features and position data of a specified face. The available data includes: face ID, face name, width, height, as well as the X and Y coordinates of the face center, X and Y coordinates of the left/right eyes, X and Y coordinates of the left/right mouth corners, and the X/Y coordinates of the nose.

The following example program can obtain the facial feature data of a face near the center of the camera frame, even if the face is not learned.

Interface Diagram

Output Result: As shown below, running the program will display the face ID and the facial feature coordinates of the face on the K10 screen. Since this face has not been learned, the face ID will be 0.

Interface Diagram

In addition to the above data, you can also obtain more face-related data, such as the total number of a specified face in the frame, the name of that face, and the related data of the first detected face (even for faces that have not been learned).

For example, for a learned face, the following example program is provided:

Interface Diagram

Output Result: As shown below, running the program will display the total number of ID1 faces in the frame, the name of that face, and the XY coordinates of the first detected ID1 face center. (The default name for a face is "Face." For how to set a name, see the Face Recognition.

Interface Diagram

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.
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 detected on the screen.
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.
Detect the number of faces that have been learned by HuskyLens 2, regardless of whether they appear in the current frame.

Was this article helpful?

TOP