FaceDetector Plugin (experimental)

This plugin uses native OS level face detection services on the device to detects human faces visible in the Video Overlay plugins camera view. Your application provides a JavaScript callback to the plugin through which the plugin returns an array of rectangles that specific the region where a face was detected. The plugin is designed to support front and back cameras in all orientations. This plugin requires the Video Overlay plugin to be installed.

This plugin will not provide face detection results if the device does not natively provide face detection support.

Note: This plugin is still in development. Face rectangle coordinates may be out of scale or translation on certain iOS iPad devices.


Installation

This plugin requires the ezAR Video Overlay plugin to be installed for it to operate. Thus plugin may be installed using any Cordova plugin compliant tools.

   example - from commandline enter
     cordova plugin add path-to-plugins/com.ezartech.ezar.flashlight
     cordova plugin add path-to-plugins/com.ezartech.ezar.videoOverlay

Use-Cases & Snippets

The flashlight plugin has a very simple api and operation. 

Start face detection

This snippet illustrates enabling face detection. Notice that watchFaces() is called after successfully initializing the VideoOverlay plugin and starting a camera.  Provide a callback function to watchFaces that repeatedly receives an array of face rectangles until clearFaces() is called or the camera is stopped.

 ezar.initializeVideoOverlay(
  function() {
    ezar.getFrontCamera().start(             
      function() {
        ezar.watchFaces(onFaces,handleError);
      },
      handleError) //end camera start
    handleError);
    
//face detection callback, receives array of face rectangles 
function onFaces(facesArray) {
  console.log('faces cnt: ', facesArray.length);
  for (i=0; i < facesArray.length; i++) {
    var face = facesArray[i];
    console.log('face: ', face.left, face.top, face.right, face.bottom);
  }
}
    
//general error handler
function handleError(errMsg) {
  alert('Error: " + errMsg);
}

Stop face detection

ezar.clearFacesWatch(
  function() {
    //success, do something 
  },
  function(error) {
    alert("clearFaces failed");
  }; 

updated 20160915

Plugins
  Video Overlay
  Face Detection
  Snapshot
  Flashlight

 

FaceDetector Plugin JavaScript API

Access the FaceDetector JavaScript api through the global ezar.  The Video Overlay plugin must be installed and a camera activated before calling watchFaces() function. 

facedetector.js module

watchFaces(successCB(facesArray),errorCB)

Start face detection. The plugin will continuously return an array of rectangles to the successCB function for each face detected in the VideoOverlay camera view. If face detection is not supported the errorCB will be invoked with an error message. Use clearFaces() to stop face detection.

parameters

  • successCB callback function, receives array of face rectangles {left, top, right, bottom}[]  
  • errorCB callback function (optional)
clearFacesWatch(successCB,errorCB)

Discontinue face detection.

parameters

  • successCB callback function  (optional)
  • errorCB callback function with String error message parameter (optional)