FaceTrackingModule Module

The FaceTrackingModule class enables facial movement and expression detection.

Usage

const FaceTracking = require('FaceTracking');

Properties

PropertyDescription

count

(get) count: ScalarSignal (set) (Not Available)

Returns a ScalarSignal representing the number of faces tracked in the scene.

Methods

MethodDescription

face

face(index: number): Face

Returns the Face object from the detected face array at the specified index.

Classes

ClassDescription

Cheek

The Cheek class exposes the details of a detected cheek.

Chin

The Chin class exposes the details of a detected chin.

Eye

The Eye class exposes the details of a detected eye.

Eyebrow

The Eyebrow class exposes the details of a detected eyebrow.

Face

The Face class exposes details of a detected face.

Forehead

The Forehead class exposes the details of a detected forehead.

Mouth

The Mouth class exposes the details of a detected mouth.

Nose

The Nose class exposes the details of a detected nose.

Example

The following example demonstrates how to work with the face tracking module.

const Reactive = require('Reactive');
const DeviceMotion = require('DeviceMotion');
const Scene = require('Scene');
const FaceTracking = require('FaceTracking');
const Time = require('Time');

const fd = Scene.root.child('Device').child('Camera').child('Focal Distance');

// EXAMPLE: Bind a scene object's transform properties to the face's.
var boundPlane = fd.child('boundPlane');

function bindPlaneToFace() {
	var face = FaceTracking.face(0);
	boundPlane.transform.rotationX = face.cameraTransform.rotationZ;
	boundPlane.transform.rotationY = face.cameraTransform.rotationX;
	boundPlane.transform.rotationZ = face.cameraTransform.rotationY;
}


// EXAMPLE: Monitor facial features to trigger new activity.
var particleEmitter = fd.child('particleEmitter');
function trackMouthOpen() {
	var face = FaceTracking.face(0);
	face.mouth.openness.multiTrigger(0.3).subscribe(function(e) {
		particleEmitter.birthrate = 20;
		Time.setTimeout(function(e) {
			particleEmitter.birthrate = 0;
		}, 1000);
	});
}

// These calls are needed because if the effect starts with a face
// in the scene, the monitor() call below will not fire an event
// until the face count changes.
bindPlaneToFace();
trackMouthOpen();

FaceTracking.count.monitor().subscribe(function (updatedCount) {
	if (updatedCount.newValue > 0) {
		bindPlaneToFace();
		trackMouthOpen();
	}
});