Face Detector

Detects the count of faces in a video stream. The event listener collects the data in a JSON object as FaceAI detects the faces.

Method

To start or stop detecting faces in a video stream.

  • Class: EnxFaceAI
  • Method: -(void)enableFaceDetector:(BOOL)enable;

Parameter

  • enable: Boolean: Set it to true to enable or start Face Detector analysis. Otherwise, set it to false.

Delegate Method

  • FaceAI:didFaceDetectorData:value: This method is received repeatedly with Face Detection Analysis data as a JSON object.

JSON Object: Received with Face Detection Analysis data.

{
faces: Array(n),
rects: Array(n),
status: string,
fullFrameDetection: Boolean,
totalFaces: Number,
totalFacesChangedFrom: Number | undefined
}

Analysis Data Explanation

  • faces : Array. The detected faces in form of ImageData objects (zero or one; or multiple faces, if fullFrameDetection is true)
  • rects : Array of objects. Describes the bounding boxes (zero or one; or multiple rects, if fullFrameDetection is true)
    • x : Upper left point x coordinate
    • y : Upper left point y coordinate
    • width : Width of the bounding box
    • height : Height of the bounding box
  • status : String. Its status of the face tracker
    • INIT : Detector initializing; zero or many faces could be returned
    • TRACK_OK : Detector is correctly tracking one face; one face is returned
    • RECOVERING : Detector lost a face and attempting to recover and continue tracking; zero faces are returned
  • fullFrameDetection : Boolean. It is true when detection was full-frame and multiple faces can be returned, false otherwise.
  • totalFaces : Number. It represents the total number filtered of faces detected, smoothened over an interval of time. By default, one face is the maximum number. If multi-face is enabled, the maximum is 6. This output is not synchronized with faces and rects arrays, do not use it to count their lengths!
  • totalFacesChangedFrom : Number. Optional. When there is a significant change in the number of faces, it is defined and represents the previous number of faces. In case no change occurred, it is undefined. This output is not synchronized with faces and rects arrays.

Note: If you notice false positives in the events, that is, a face is detected as present but it is not actually present, you can further filter the results by the confidence property of the elements contained in the rects array (for example, rects[0].confidence > 10).

Sample Code

// Start Face Detector
[FaceAI enableFaceDetector:true];
- (void)FaceAI:(EnxFaceAI *_Nullable)FaceAI didFaceDetectorData:(NSString *_Nullable)type value:(NSString *_Nullable)value{
}