classdoc: [VideoDetector]

A common use of the SDK is to process previously captured video files. The VideoDetector helps streamline this effort by decoding and processing frames from a video file.

Creating the detector

The VideoDetector constructor expects three parameters { context, filePath, maxNumFaces and faceDetectorMode }

public VideoDetector(
                The application context.
              Context context,

                String represents the file path on device memory.
              String filePath,

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

                Face detector configuration - If not specified, defaults to FaceDetectorMode.SMALL_FACES
                  FaceDetectorMode.LARGE_FACES=Faces occupying large portions of the frame
                  FaceDetectorMode.SMALL_FACES=Faces occupying small portions of the frame
              FaceDetectorMode faceConfig


String fileName = "/sdcard/movie.mp4";
VideoDetector detector = new VideoDetector(this, fileName);

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 [java]

public class MyActivity implements Detector.FaceListener {
  protected void onCreate(Bundle savedInstanceState) {

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 [java]

public class MyActivity implements Detector.ImageListener {
  protected void onCreate(Bundle savedInstanceState) {

  //The follow code sample shows an example of how to retrieve metric values from the Face object
  public void onImageResults(List<Face> faces, Frame image,float timestamp) {

      if (faces == null)
          return; //frame was not processed

      if (faces.size() == 0)
          return; //no face found

      //For each face found
      for (int i = 0 ; i < faces.size() ; i++) {
        Face face = faces.get(i);

        int faceId = face.getId();

        Face.GENDER genderValue = face.appearance.getGender();
        Face.GLASSES glassesValue = face.appearance.getGlasses();
        Face.AGE ageValue = face.appearance.getAge();
        Face.ETHNICITY ethnicityValue = face.appearance.getEthnicity();

        //Some Emoji
        float smiley = face.emojis.getSmiley();
        float laughing = face.emojis.getLaughing();
        float wink = face.emojis.getWink();

        //Some Emotions
        float joy = face.emotions.getJoy();
        float anger = face.emotions.getAnger();
        float disgust = face.emotions.getDisgust();

        //Some Expressions
        float smile = face.expressions.getSmile();
        float brow_furrow = face.expressions.getBrowFurrow();
        float brow_raise = face.expressions.getBrowRaise();

        float interocular_distance = face.measurements.getInterocularDistance();
        float yaw = face.measurements.orientation.getYaw();
        float roll = face.measurements.orientation.getRoll();
        float pitch = face.measurements.orientation.getPitch();

        //Face feature points coordinates
        PointF[] points = face.getFacePoints();


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, emojis, or appearances:


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:


To check if the detector is running,

bool running = detector.isRunning();

Once start() is called, the video frames are decoded, processed and the callback functions are used to notify of the decoded frames, results.

Stopping the detector

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


Be sure to always call stop() following a successful call to start() (including for example, in circumstances where you abort processing, such as in exception catch blocks). This ensures that resources held by the Detector instance are released.

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