Face Emotion Recognition Example
Face emotion recognition on HUSKYLENS 2 lets you instantly detect seven preset emotions and stream their IDs and counts to UNIHIKER, like a smart mirror that reads mood in real time
1.Face Emotion Recognition
Before You Start:
1.1 Face Emotion Recognition - Output Relevant Data
Under the Face Emotion Recognition function, HUSKYLENS 2 can recognize 7 specific emotions: angry (ID 1), disgust (ID 2), fear (ID 3), happy (ID 4), neutral (ID 5), sad (ID 6), and surprise (ID 7). These emotions have already been learned by HUSKYLENS 2 at the factory, so users do not need to learn them manually again. For detailed function instructions, please see Face Emotion Recognition.
The example program below can be used to count the total number of all recognized emotions in the current HUSKYLENS 2 camera frame and output the ID of a specific emotion.
Example Program:
from unihiker import GUI
from pinpong.board import Board
from dfrobot_huskylensv2 import *
u_gui=GUI()
Board().begin()
huskylens = HuskylensV2_I2C()
huskylens.knock()
huskylens.switchAlgorithm(ALGORITHM_EMOTION_RECOGNITION)
line1=u_gui.draw_text(text="",x=0,y=0,font_size=20, color="#0000FF")
line2=u_gui.draw_text(text="",x=0,y=40,font_size=20, color="#0000FF")
line3=u_gui.draw_text(text="",x=0,y=80,font_size=20, color="#0000FF")
while True:
huskylens.getResult(ALGORITHM_EMOTION_RECOGNITION)
if (huskylens.available(ALGORITHM_EMOTION_RECOGNITION)):
line1.config(text=(str("Faces count:") + str((huskylens.getCachedResultNum(ALGORITHM_EMOTION_RECOGNITION)))))
line2.config(text=(str("Center face ID:") + str((huskylens.getCachedCenterResult(ALGORITHM_EMOTION_RECOGNITION).ID if huskylens.getCachedCenterResult(ALGORITHM_EMOTION_RECOGNITION) else -1))))
line3.config(text=(str("Firsr face ID:") + str((huskylens.getCachedResultByIndex(ALGORITHM_EMOTION_RECOGNITION, 1-1).ID if huskylens.getCachedResultByIndex(ALGORITHM_EMOTION_RECOGNITION, 1-1) else -1))))
Click 'Run' in Mind+ and wait for the program to upload.
When any of the seven emotions above appear in the camera frame, observe the HUSKYLENS 2 screen. It will frame the emotion and display its ID, name, and confidence. At the same time, the UNIHIKER M10 (User provided K10, but document context is M10) screen will display the result data output by the program.
Output Result: As shown below, it outputs the specified emotion ID and the total number of emotions in the frame, as required by the program.
1.2 Get Data for a Specific Emotion in the Frame
When multiple emotions with the same ID appear in the frame, the following example program can be used to gather relevant data for that emotion ID.
from unihiker import GUI
from pinpong.board import Board
from dfrobot_huskylensv2 import *
u_gui=GUI()
Board().begin()
huskylens = HuskylensV2_I2C()
huskylens.knock()
huskylens.switchAlgorithm(ALGORITHM_EMOTION_RECOGNITION)
line1=u_gui.draw_text(text="",x=0,y=0,font_size=20, color="#0000FF")
line2=u_gui.draw_text(text="",x=0,y=40,font_size=20, color="#0000FF")
line3=u_gui.draw_text(text="",x=0,y=80,font_size=20, color="#0000FF")
while True:
huskylens.getResult(ALGORITHM_EMOTION_RECOGNITION)
if (huskylens.available(ALGORITHM_EMOTION_RECOGNITION)):
line1.config(text=(str("Faces count:") + str((huskylens.getCachedResultNum(ALGORITHM_EMOTION_RECOGNITION)))))
line2.config(text=(str("Center face ID:") + str((huskylens.getCachedCenterResult(ALGORITHM_EMOTION_RECOGNITION).ID if huskylens.getCachedCenterResult(ALGORITHM_EMOTION_RECOGNITION) else -1))))
line3.config(text=(str("Firsr face ID:") + str((huskylens.getCachedResultByIndex(ALGORITHM_EMOTION_RECOGNITION, 1-1).ID if huskylens.getCachedResultByIndex(ALGORITHM_EMOTION_RECOGNITION, 1-1) else -1))))
Output Result:As shown below, when multiple emotions with a specific ID appear in the frame, it can acquire the total count, name, and coordinates of a specific emotion under that ID, among other data.
Was this article helpful?
