Skip to content

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:

python
face_expression = FaceExpression(0)
# When there are multiple instances
face_expression_1 = FaceExpression(1)

Parameters ​

NameKindDescriptionRange / TypeDefault
indexDropdown optionInstance number (starting from 0)Integer 0 or greater0

Select the camera device ​

Sets the camera to use for age, gender, and expression recognition.

device

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionCamera device nameSystem camera label-

Python ​

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.

load_model

Parameters ​

NameKindDescriptionRange / TypeDefault
waitCheckboxWhether to wait for loading to completeTRUE / FALSETRUE

Python ​

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.

detect_once

Parameters ​

(none)

Python ​

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.

detect_continuous

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionActionstart, stop-

Python ​

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.

display

Parameters ​

NameKindDescriptionRange / TypeDefault
onDropdown optionDisplay ON / OFFshow (on=True), hide (off=False)TRUE

Python ​

python
face_expression = FaceExpression(0)

face_expression.display(True)
face_expression.display(False)

Age ​

The age

age

Parameters ​

(none)

Python ​

python
face_expression = FaceExpression(0)

face_expression.age()

Gender ​

The gender

gender

Parameters ​

(none)

Python ​

python
face_expression = FaceExpression(0)

face_expression.gender()

Expression ​

The expression

expression

Parameters ​

(none)

Python ​

python
face_expression = FaceExpression(0)

face_expression.expression()

Whether the gender was detected ​

Whether the gender was recognized

gender_detected

Parameters ​

(none)

Python ​

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).

gender_check

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionGendermale, female-

Python ​

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

gender_confidence

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionGendermale, female-

Python ​

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

expression_detected

Parameters ​

(none)

Python ​

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).

expression_check

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionExpressionangry, disgusted, fearful, happy, neutral, sad, surprised-

Python ​

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

expression_confidence

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionExpressionangry, disgusted, fearful, happy, neutral, sad, surprised-

Python ​

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.

model_state

Parameters ​

(none)

Python ​

python
face_expression = FaceExpression(0)

face_expression.model_state()