EmotiEffCppLib
Cpp implementation of Emotion Efficient Library
Loading...
Searching...
No Matches
EmotiEffLib::EmotiEffLibRecognizer Class Referenceabstract

Base class for emotion and engagement recognition. More...

#include <facial_analysis.h>

Inheritance diagram for EmotiEffLib::EmotiEffLibRecognizer:
Collaboration diagram for EmotiEffLib::EmotiEffLibRecognizer:

Public Member Functions

virtual ~EmotiEffLibRecognizer ()=default
virtual EmotiEffLibRes classifyEmotions (const xt::xarray< float > &features, bool logits=true)=0
 Classifies emotions based on extracted features.
virtual EmotiEffLibRes classifyEngagement (const xt::xarray< float > &features)=0
 Classifies engagement based on extracted features.
virtual xt::xarray< float > extractFeatures (const cv::Mat &faceImg)=0
 Extracts features from a single face image.
virtual xt::xarray< float > extractFeatures (const std::vector< cv::Mat > &faceImgs)
 Extracts features from a sequence of face images.
std::string getEmotionClassById (int idx)
 Gets the emotion class name by index.
std::string getEngagementClassById (int idx)
 Gets the engagement class name by index.
virtual EmotiEffLibRes predictEmotions (const cv::Mat &faceImg, bool logits=true)=0
 Predicts emotions for a single face image.
virtual EmotiEffLibRes predictEmotions (const std::vector< cv::Mat > &faceImgs, bool logits=true)
 Predicts emotions for a sequence of face images.
virtual EmotiEffLibRes predictEngagement (const std::vector< cv::Mat > &faceImgs)=0
 Predicts engagement for a sequence of face images.

Static Public Member Functions

static std::unique_ptr< EmotiEffLibRecognizer > createInstance (const EmotiEffLibConfig &config)
 Creates an instance of the EmotiEffLibRecognizer with the specified configuration.
static std::unique_ptr< EmotiEffLibRecognizer > createInstance (const std::string &backend, const std::string &fullPipelineModelPath)
 Creates an instance of the EmotiEffLibRecognizer with the specified backend and model path.

Protected Member Functions

virtual void configParser (const EmotiEffLibConfig &config)=0
 Parses the configuration to initialize the recognizer.
xt::xarray< float > engagementFeaturesPreprocess (const xt::xarray< float > features)
 Preprocesses engagement features.
virtual void initRecognizer (const std::string &modelPath)
 Initializes the internal state of recognizer based on a modelPath.
virtual xt::xarray< float > preprocess (const cv::Mat &img)=0
 Preprocesses an image for feature extraction.
EmotiEffLibRes processEmotionScores (const xt::xarray< float > &scores, bool logits)
 Common method to processes emotion scores and generate classification results.
EmotiEffLibRes processEngagementScores (const xt::xarray< float > &scores)
 Common method to processes engagement scores and generate classification results.

Protected Attributes

int classifierIdx_ = -1
 Index of the classifier model in the array with models.
int engagementClassifierIdx_ = -1
 Index of the engagement classifier model in the array with models.
const int engagementSlidingWindowSize_ = 128
 Sliding window size for engagement prediction.
int featureExtractorIdx_ = -1
 Index of the model for features extraction in the array with models.
int fullPipelineModelIdx_ = -1
 Index of the full pipeline model in the array with models.
std::vector< std::string > idxToEmotionClass_
 Emotion class names.
std::vector< std::string > idxToEngagementClass_ = {"Distracted", "Engaged"}
 Engagement class names.
int imgSize_
 Input image size.
bool isMtl_
 Whether the model is multi-task learning (MTL).
std::string modelName_ = ""
 Name of the model.

Detailed Description

Base class for emotion and engagement recognition.

This class provides the interface for emotion and engagement recognition using different backends. It supports feature extraction, emotion classification, and engagement prediction.

Definition at line 121 of file facial_analysis.h.

Constructor & Destructor Documentation

◆ ~EmotiEffLibRecognizer()

virtual EmotiEffLib::EmotiEffLibRecognizer::~EmotiEffLibRecognizer ( )
virtualdefault

Member Function Documentation

◆ classifyEmotions()

virtual EmotiEffLibRes EmotiEffLib::EmotiEffLibRecognizer::classifyEmotions ( const xt::xarray< float > & features,
bool logits = true )
pure virtual

Classifies emotions based on extracted features.

Parameters
featuresThe extracted features.
logitsWhether to return raw logits or apply softmax.
Returns
The classification results.

Implemented in EmotiEffLib::EmotiEffLibRecognizerOnnx, and EmotiEffLib::EmotiEffLibRecognizerTorch.

◆ classifyEngagement()

virtual EmotiEffLibRes EmotiEffLib::EmotiEffLibRecognizer::classifyEngagement ( const xt::xarray< float > & features)
pure virtual

Classifies engagement based on extracted features.

Parameters
featuresThe extracted features.
Returns
The classification results.

Implemented in EmotiEffLib::EmotiEffLibRecognizerOnnx, and EmotiEffLib::EmotiEffLibRecognizerTorch.

◆ configParser()

virtual void EmotiEffLib::EmotiEffLibRecognizer::configParser ( const EmotiEffLibConfig & config)
protectedpure virtual

Parses the configuration to initialize the recognizer.

Parameters
configThe configuration structure.

◆ createInstance() [1/2]

std::unique_ptr< EmotiEffLibRecognizer > EmotiEffLib::EmotiEffLibRecognizer::createInstance ( const EmotiEffLibConfig & config)
static

Creates an instance of the EmotiEffLibRecognizer with the specified configuration.

Parameters
configThe configuration structure containing backend and model paths.
Returns
A unique pointer to the created EmotiEffLibRecognizer instance.

Definition at line 59 of file facial_analysis.cpp.

◆ createInstance() [2/2]

std::unique_ptr< EmotiEffLibRecognizer > EmotiEffLib::EmotiEffLibRecognizer::createInstance ( const std::string & backend,
const std::string & fullPipelineModelPath )
static

Creates an instance of the EmotiEffLibRecognizer with the specified backend and model path.

Parameters
backendThe inference backend to use ("torch" or "onnx").
fullPipelineModelPathPath to the full pipeline model file.
Returns
A unique pointer to the created EmotiEffLibRecognizer instance.

Definition at line 45 of file facial_analysis.cpp.

◆ engagementFeaturesPreprocess()

xt::xarray< float > EmotiEffLib::EmotiEffLibRecognizer::engagementFeaturesPreprocess ( const xt::xarray< float > features)
protected

Preprocesses engagement features.

Parameters
featuresThe extracted features.
Returns
The preprocessed features.

Definition at line 185 of file facial_analysis.cpp.

◆ extractFeatures() [1/2]

virtual xt::xarray< float > EmotiEffLib::EmotiEffLibRecognizer::extractFeatures ( const cv::Mat & faceImg)
pure virtual

Extracts features from a single face image.

Parameters
faceImgThe input face image.
Returns
An array of extracted features.

Implemented in EmotiEffLib::EmotiEffLibRecognizerOnnx, and EmotiEffLib::EmotiEffLibRecognizerTorch.

◆ extractFeatures() [2/2]

xt::xarray< float > EmotiEffLib::EmotiEffLibRecognizer::extractFeatures ( const std::vector< cv::Mat > & faceImgs)
virtual

Extracts features from a sequence of face images.

Parameters
faceImgsA list of input face images.
Returns
An array of extracted features.

Definition at line 71 of file facial_analysis.cpp.

◆ getEmotionClassById()

std::string EmotiEffLib::EmotiEffLibRecognizer::getEmotionClassById ( int idx)
inline

Gets the emotion class name by index.

Parameters
idxThe index of the emotion class.
Returns
The name of the emotion class.

Definition at line 156 of file facial_analysis.h.

◆ getEngagementClassById()

std::string EmotiEffLib::EmotiEffLibRecognizer::getEngagementClassById ( int idx)
inline

Gets the engagement class name by index.

Parameters
idxThe index of the engagement class.
Returns
The name of the engagement class.

Definition at line 164 of file facial_analysis.h.

◆ initRecognizer()

void EmotiEffLib::EmotiEffLibRecognizer::initRecognizer ( const std::string & modelPath)
protectedvirtual

Initializes the internal state of recognizer based on a modelPath.

Parameters
modelPathPath to the model file.

Definition at line 104 of file facial_analysis.cpp.

◆ predictEmotions() [1/2]

virtual EmotiEffLibRes EmotiEffLib::EmotiEffLibRecognizer::predictEmotions ( const cv::Mat & faceImg,
bool logits = true )
pure virtual

Predicts emotions for a single face image.

Parameters
faceImgThe input face image.
logitsWhether to return raw logits or apply softmax.
Returns
The prediction results.

Implemented in EmotiEffLib::EmotiEffLibRecognizerOnnx, and EmotiEffLib::EmotiEffLibRecognizerTorch.

◆ predictEmotions() [2/2]

EmotiEffLibRes EmotiEffLib::EmotiEffLibRecognizer::predictEmotions ( const std::vector< cv::Mat > & faceImgs,
bool logits = true )
virtual

Predicts emotions for a sequence of face images.

Parameters
faceImgsA list of input face images.
logitsWhether to return raw logits or apply softmax.
Returns
The prediction results.

Definition at line 86 of file facial_analysis.cpp.

◆ predictEngagement()

virtual EmotiEffLibRes EmotiEffLib::EmotiEffLibRecognizer::predictEngagement ( const std::vector< cv::Mat > & faceImgs)
pure virtual

Predicts engagement for a sequence of face images.

Parameters
faceImgsA list of input face images.
Returns
The prediction results.

Implemented in EmotiEffLib::EmotiEffLibRecognizerOnnx, and EmotiEffLib::EmotiEffLibRecognizerTorch.

◆ preprocess()

virtual xt::xarray< float > EmotiEffLib::EmotiEffLibRecognizer::preprocess ( const cv::Mat & img)
protectedpure virtual

Preprocesses an image for feature extraction.

Parameters
imgThe input image.
Returns
The preprocessed image as an array.

◆ processEmotionScores()

EmotiEffLibRes EmotiEffLib::EmotiEffLibRecognizer::processEmotionScores ( const xt::xarray< float > & scores,
bool logits )
protected

Common method to processes emotion scores and generate classification results.

Parameters
scoresThe raw emotion scores.
logitsWhether to return raw logits or apply softmax.
Returns
The processed classification results.

Definition at line 133 of file facial_analysis.cpp.

◆ processEngagementScores()

EmotiEffLibRes EmotiEffLib::EmotiEffLibRecognizer::processEngagementScores ( const xt::xarray< float > & scores)
protected

Common method to processes engagement scores and generate classification results.

Parameters
scoresThe raw engagement scores.
Returns
The processed classification results.

Definition at line 171 of file facial_analysis.cpp.

Member Data Documentation

◆ classifierIdx_

int EmotiEffLib::EmotiEffLibRecognizer::classifierIdx_ = -1
protected

Index of the classifier model in the array with models.

Definition at line 294 of file facial_analysis.h.

◆ engagementClassifierIdx_

int EmotiEffLib::EmotiEffLibRecognizer::engagementClassifierIdx_ = -1
protected

Index of the engagement classifier model in the array with models.

Definition at line 296 of file facial_analysis.h.

◆ engagementSlidingWindowSize_

const int EmotiEffLib::EmotiEffLibRecognizer::engagementSlidingWindowSize_ = 128
protected

Sliding window size for engagement prediction.

Definition at line 298 of file facial_analysis.h.

◆ featureExtractorIdx_

int EmotiEffLib::EmotiEffLibRecognizer::featureExtractorIdx_ = -1
protected

Index of the model for features extraction in the array with models.

Definition at line 292 of file facial_analysis.h.

◆ fullPipelineModelIdx_

int EmotiEffLib::EmotiEffLibRecognizer::fullPipelineModelIdx_ = -1
protected

Index of the full pipeline model in the array with models.

Definition at line 290 of file facial_analysis.h.

◆ idxToEmotionClass_

std::vector<std::string> EmotiEffLib::EmotiEffLibRecognizer::idxToEmotionClass_
protected

Emotion class names.

Definition at line 302 of file facial_analysis.h.

◆ idxToEngagementClass_

std::vector<std::string> EmotiEffLib::EmotiEffLibRecognizer::idxToEngagementClass_ = {"Distracted", "Engaged"}
protected

Engagement class names.

Definition at line 300 of file facial_analysis.h.

◆ imgSize_

int EmotiEffLib::EmotiEffLibRecognizer::imgSize_
protected

Input image size.

Definition at line 306 of file facial_analysis.h.

◆ isMtl_

bool EmotiEffLib::EmotiEffLibRecognizer::isMtl_
protected

Whether the model is multi-task learning (MTL).

Definition at line 304 of file facial_analysis.h.

◆ modelName_

std::string EmotiEffLib::EmotiEffLibRecognizer::modelName_ = ""
protected

Name of the model.

Definition at line 288 of file facial_analysis.h.


The documentation for this class was generated from the following files: