Face Expression
Instance declaration
When you add a Face Expression block to the workspace, the following instance declaration is automatically inserted into the Python code:
face_expression = FaceExpression(0)
# When there are multiple instances
face_expression_1 = FaceExpression(1)Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| index | Dropdown option | Instance number (starting from 0) | Integer 0 or greater | 0 |
Select the camera device
Sets the camera to use for age, gender, and expression recognition.

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| unit | Dropdown option | Camera device name | System camera label | - |
Python
face_expression = FaceExpression(0)
face_expression.device('')Load the model
Loads the trained age, gender, and expression model. This step is required in order to use the features of the 'Face Expression' module.

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| wait | Checkbox | Whether to wait for loading to complete | TRUE / FALSE | TRUE |
Python
face_expression = FaceExpression(0)
face_expression.load_model(wait=True)Detect once
Analyzes the faces currently on screen and shows the predicted age, gender, and expression just once.

Parameters
(none)
Python
face_expression = FaceExpression(0)
face_expression.detect_once()Start / stop continuous detection
Keeps analyzing the faces currently on screen and shows the predicted age, gender, and expression on the screen.

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| unit | Dropdown option | Action | start, stop | - |
Python
face_expression = FaceExpression(0)
# unit = "start"
face_expression.detect_continuous()
# unit = "stop"
face_expression.stop()Show the detection result
Decides whether or not to show the age, gender, and expression recognition result on the camera screen.

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| on | Dropdown option | Display ON / OFF | show (on=True), hide (off=False) | TRUE |
Python
face_expression = FaceExpression(0)
face_expression.display(True)
face_expression.display(False)Age
The age

Parameters
(none)
Python
face_expression = FaceExpression(0)
face_expression.age()Gender
The gender

Parameters
(none)
Python
face_expression = FaceExpression(0)
face_expression.gender()Expression
The expression

Parameters
(none)
Python
face_expression = FaceExpression(0)
face_expression.expression()Whether the gender was detected
Whether the gender was recognized

Parameters
(none)
Python
face_expression = FaceExpression(0)
face_expression.gender_detected()Is it a particular gender?
Returns whether the recognized gender matches the specified value as true (True) / false (False).

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| unit | Dropdown option | Gender | male, female | - |
Python
face_expression = FaceExpression(0)
face_expression.is_gender('male')
face_expression.is_gender('female')Gender confidence
The probability (confidence) that it is the selected gender

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| unit | Dropdown option | Gender | male, female | - |
Python
face_expression = FaceExpression(0)
face_expression.gender_confidence('male')
face_expression.gender_confidence('female')Whether the expression was detected
Whether the expression was recognized

Parameters
(none)
Python
face_expression = FaceExpression(0)
face_expression.expression_detected()Is it a particular expression?
Returns whether the recognized expression matches the specified value as true (True) / false (False).

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| unit | Dropdown option | Expression | angry, disgusted, fearful, happy, neutral, sad, surprised | - |
Python
face_expression = FaceExpression(0)
face_expression.is_expression('happy')
face_expression.is_expression('sad')Expression confidence
The probability (confidence) that it is the selected expression

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| unit | Dropdown option | Expression | angry, disgusted, fearful, happy, neutral, sad, surprised | - |
Python
face_expression = FaceExpression(0)
face_expression.expression_confidence('happy')
face_expression.expression_confidence('angry')Model state
Returns the loading state of the age, gender, and expression model.
It returns 0 if it has not been loaded yet, 1 while it is loading, and 2 once loading is complete.

Parameters
(none)
Python
face_expression = FaceExpression(0)
face_expression.model_state()