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 detect the number of faces in a video stream.
Method: EnxFaceAI.startFaceDetector(callback)
Parameter
callback
: Callback to know that processing request has been accepted.
Event Listener
face-detector
: This event notification 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 coordinatey
: Upper left point y coordinatewidth
: Width of the bounding boxheight
: Height of the bounding box
status
: String. Its status of the face trackerINIT
: Detector initializing; zero or many faces could be returnedTRACK_OK
: Detector is correctly tracking one face; one face is returnedRECOVERING
: 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 DetectorfaceAI.startFaceDetector((res) => {if (res.result === 0) {window.addEventListener("face-detector", (evt) => {console.log(evt.detail, "face-detector");});}});