classdoc: PhotoDetector [c++], [c#]

The PhotoDetectorclass is used for streamlining the processing of still images. Since photos lack any continuity over time, the expression and emotion detection is performed independently on each frame and the timestamp is ignored. Due to this fact, the underlying emotion detection may return different results than the video based detectors.

Creating the detector

The PhotoDetector constructor expects two parameters { maxNumFaces and faceConfig }

                The maximum number of faces to track
                If not specified, DEFAULT_MAX_NUM_FACES=1
              unsigned int maxNumFaces,

                Face detector configuration
                If not specified, defaults to FaceDetectorMode.SMALL_FACES

                FaceDetectorMode.LARGE_FACES=Faces occupying large portions of the photo
                FaceDetectorMode.SMALL_FACES=Faces occupying small portions of the photo
              FaceDetectorMode faceConfig


PhotoDetector detector = new PhotoDetector(2);

Configuring the detector

In order to initialize the detector, a valid location of the data folder must be specified:

Data folder

The Affdex classifier data files are used in frame analysis processing. These files are supplied as part of the SDK. The location of the data files on the physical storage needs to be passed to a detector in order to initialize it by calling the following with the fully qualified path to the folder containing them:

String classifierPath="C:\\Program Files(x86)\\Affectiva\\AffdexSDK\\data"

Configuring the callback functions

The Detectors use callback functions defined in interface classes to communicate events and results. The event listeners need to be initialized before the detector is started: The FaceListener is a client callback interface which sends notification when the detector has started or stopped tracking a face. Call setFaceListener to set the FaceListener:

classdoc: FaceListener [c++], [c#]

class MyApp : Affdex.FaceListener {
  MyApp() {

The ImageListener is a client callback interface which delivers information about an image which has been handled by the Detector. Call setImageListener to set the ImageListener:

classdoc: ImageListener [c++], [c#]

class MyApp : Affdex.ImageListener {
  MyApp() {

The ProcessStatusListener is a callback interface which provides information regarding the processing state of the detector. Call setProcessStatusListener to set the ProcessStatusListener:

classdoc: ProcessStatusListener [c++], [c#]

class MyApp : Affdex.ProcessStatusListener {
  MyApp() {

Choosing the classifiers

The next step is to turn on the detection of the metrics needed. For example, to turn on or off the detection of the smile and joy classifiers:


To turn on or off the detection of all expressions, emotions or emojis:


To check the status of a classifier at any time, for example smile:


Initializing the detector

After a detector is configured using the methods above, the detector initialization can be triggered by calling the start method:


Processing a frame

After successfully initializing the detector using the start method. The frames can be passed to the detector by calling the process method. The process method expects a Frame

classdoc: Frame [c++], [c#]

detector.process(Frame frame);

Stopping the detector

At the end of the interaction with the detection. Stopping the detector can be done as follows:


The processing state can be reset. This method resets the context of the video frames. Additionally Face IDs and Timestamps are set to zero (0):