Skip to main content
Version: 3.16.0 (latest)

Face Estimation

In this section you will learn how to integrate Emotion and Gender estimators to your C++ project.

Emotion Estimation (C++)#

Requirements#

  • Windows x86 64-bit or Linux x86 64-bit system.
  • Installed Face SDK package windows_x86_64 or linux_x86_64 (see Getting Started).

1. Creating an Emotion Estimator#

1.1. To create an Emotion Estimator, follow steps 1-3 described in Creating a Processing Block and specify the values:

  • "EMOTION_ESTIMATOR" for the "unit_type" key;
  • path to Emotion Estimator model file for the "model_path" key.
configCtx["unit_type"] = "EMOTION_ESTIMATOR";
// default path to Emotion Estimator model file is "share/faceanalysis/emotion.enc" in the package's root directory
configCtx["model_path"] = "share/faceanalysis/emotion.enc";

1.2. Create an Emotion Estimator Processing block:

pbio::ProcessingBlock emotionEstimator = service->createProcessingBlock(configCtx);

2. Emotion Estimation#

2.1. Create a Context container ioData for input-output data using the createContext() method:

auto ioData = service->createContext();

2.2. Create a Context container imgCtx with RGB-image following the steps described on Creating a Context container with RGB-image.

2.3. Put input image to the input-output data container:

ioData["image"] = imgCtx;

2.4. Call the emotionEstimator and pass the context with source image ioData:

emotionsEstimator(ioData);

The result of calling emotionEstimator() will be appended to ioData container. The format of the output data is presented as a list of objects with the "objects" key. This list object has the "class" key with the "face" value.

/*
{
"objects": [{ "id": {"type": "long", "minimum": 0}
"class": "face",
"emotions" : [
"emotion": {
"enum": ["ANGRY", "DISGUSTED", "SCARED", "HAPPY", "NEUTRAL", "SAD", "SURPRISED"]
}
"confidence": {"type": "double", "minimum": 0, "maximum": 1}
]
}]
}
*/

3. GPU Acceleration#

Emotion Estimator can be used with GPU acceleration (CUDA). For more information, please follow this link.

Age Estimation (C++)#

Requirements#

  • Windows x86 64-bit or Linux x86 64-bit system.
  • Installed Face SDK package windows_x86_64 or linux_x86_64 (see Getting Started).

1. Creating a Age Estimator#

1.1. To create an Age Estimator, follow steps 1-3 described in Creating a Processing Block and specify the values:

  • "AGE_ESTIMATOR" for the "unit_type" key;
  • path to Age Estimator model file for the "model_path" key.
configCtx["unit_type"] = "AGE_ESTIMATOR";
// default path to Age Estimator model file is "share/faceanalysis" in the Face SDK's root directory. Two versions are available - age_heavy and age_light, differing in size, quality and infer speed
configCtx["model_path"] = "share/faceanalysis/age_heavy.enc";

1.2. Create an Age Estimator Processing block:

pbio::ProcessingBlock ageEstimator = service->createProcessingBlock(configCtx);

2. Age Estimation#

2.1. Create a Context container ioData for input-output data using the createContext() method:

auto ioData = service->createContext();

2.2. Create a Context container imgCtx with RGB-image following the steps described on Creating a Context container with RGB-image.

2.3. Put input image to the input-output data container:

ioData["image"] = imgCtx;

2.4. Call the ageEstimator and pass the context ioData with source image:

ageEstimator(ioData);

The result of calling ageEstimator() will be appended to ioData container.

/*
{
"objects": [{ "id": {"type": "long", "minimum": 0}
"class": "face",
"age": {"type": "long", "minimum": 0}
}]
}
*/

3. GPU Acceleration#

Age Estimator can be used with GPU acceleration (CUDA). For more information, please follow this link.

Gender Estimation (C++)#

Requirements#

  • Windows x86 64-bit or Linux x86 64-bit system.
  • Installed Face SDK package windows_x86_64 or linux_x86_64 (see Getting Started).

1. Creating a Gender Estimator#

1.1. To create a Gender Estimator, follow steps 1-3 described in Creating a Processing Block and specify the values:

  • "GENDER_ESTIMATOR" for the "unit_type" key;
  • path to Gender Estimator model file for the "model_path" key.
configCtx["unit_type"] = "GENDER_ESTIMATOR";
// default path to Gender Estimator model file is "share/faceanalysis/" in the Face SDK's root directory. Two versions are available - gender_heavy and gender_light, differing in size, quality and infer speed
configCtx["model_path"] = "share/faceanalysis/gender_heavy.enc";

1.2. Create a Gender Estimator Processing block:

pbio::ProcessingBlock genderEstimator = service->createProcessingBlock(configCtx);

2. Gender Estimation#

2.1. Create a Context container ioData for input-output data using the createContext() method:

auto ioData = service->createContext();

2.2. Create a Context container imgCtx with RGB-image following the steps described on Creating a Context container with RGB-image.

2.3. Put input image to the input-output data container:

ioData["image"] = imgCtx;

2.4. Call the genderEstimator and pass the context ioData with source image:

genderEstimator(ioData);

The result of calling genderEstimator() will be appended to ioData container.

/*
{
"objects": [{ "id": {"type": "long", "minimum": 0}
"class": "face",
"gender": {
"enum": ["FEMALE", "MALE"]
}
}]
}
*/

3. GPU Acceleration#

Gender Estimator can be used with GPU acceleration (CUDA). For more information, please follow this link.

Mask Estimation (C++)#

Requirements#

  • Windows x86 64-bit or Linux x86 64-bit system.
  • Installed Face SDK package windows_x86_64 or linux_x86_64 (see Getting Started).

1. Creating a Mask Estimator#

1.1. To create a Mask Estimator, follow steps 1-3 described in Creating a Processing Block and specify the values:

  • "MASK_ESTIMATOR" for the "unit_type" key;
  • path to Age Estimator model file for the "model_path" key.
configCtx["unit_type"] = "MASK_ESTIMATOR";
// default path to Mask Estimator model file is "share/faceattributes/mask.enc" in the Face SDK's root directory.
configCtx["model_path"] = "share/faceattributes/mask.enc";

1.2. Create a Mask Estimator Processing block:

pbio::ProcessingBlock maskEstimator = service->createProcessingBlock(configCtx);

2. Mask Estimation#

2.1. Create a Context container ioData for input-output data using the createContext() method:

auto ioData = service->createContext();

2.2. Create a Context container imgCtx with RGB-image following the steps described on Creating a Context container with RGB-image.

2.3. Put input image to the input-output data container:

ioData["image"] = imgCtx;

2.4. Call the maskEstimator and pass the context ioData with source image:

maskEstimator(ioData);

The result of calling maskEstimator() will be appended to ioData container.

/*
{
"objects": [{ "id": {"type": "long", "minimum": 0}
"class": "face",
"mask": {
"value": {"type": "boolean"},
"confidence": {"double", "minimum": 0, "maximum": 1}
}
}]
}
*/

3. GPU Acceleration#

Age Estimator can be used with GPU acceleration (CUDA). For more information, please follow this link.

Last updated on