Expo

Get Started
API Reference

FaceDetector

expo-face-detector lets you use the power of the Google Mobile Vision framework to detect faces on images.

Platform Compatibility

Android DeviceAndroid EmulatoriOS DeviceiOS SimulatorWeb
Pending

Installation

expo install expo-face-detector

If you're installing this in a bare React Native app, you should also follow these additional installation instructions.

  • Android does not recognize faces that aren't aligned with the interface (top of the interface matches top of the head).

In order to configure detector's behavior modules pass a DetectionOptions object which is then interpreted by this module.
Eg. you could use the following snippet to detect faces in fast mode without detecting landmarks or whether face is smiling:
import * as React from 'react';
import { Camera } from 'expo-camera';
import * as FaceDetector from 'expo-face-detector';

const App = () => (
  <Camera
    // other props
    onFacesDetected={handleFacesDetected}
    faceDetectorSettings={{
      mode: FaceDetector.FaceDetectorMode.fast,
      detectLandmarks: FaceDetector.FaceDetectorLandmarks.none,
      runClassifications: FaceDetector.FaceDetectorClassifications.none,
      minDetectionInterval: 100,
      tracking: true,
    }}
  />
);

%%placeholder-start%%const handleFacesDetected = ({ faces }) => { ... }; %%placeholder-end%%const handleFacesDetected = ({ faces }) => {
  console.log(faces);
};

export default App;

import * as FaceDetector from 'expo-face-detector';

  • uri (string) - file:// URI to the image.
  • options (DetectionOptions) - A map of detection options.

Detect faces on a picture.

  • Promise<DetectionResult>

Returns a Promise which fulfils with DetectionResult object.

In order to configure detector's behavior modules pass a settings object which is then interpreted by this module.

NameTypeDescription
detectLandmarks
(optional)
FaceDetectorLandmarksWhether to detect and return landmarks positions on the face (ears, eyes, mouth, cheeks, nose). Use FaceDetector.FaceDetectorLandmarks.{all, none}.
minDetectionInterval
(optional)
numberMinimal interval in milliseconds between two face detection events being submitted to JS. Use, when you expect lots of faces for long time and are afraid of JS Bridge being overloaded.

Default: `0`
mode
(optional)
FaceDetectorModeWhether to detect faces in fast or accurate mode. Use FaceDetector.FaceDetectorMode.{fast, accurate}.
runClassifications
(optional)
FaceDetectorClassificationsWhether to run additional classifications on detected faces (smiling probability, open eye probabilities). Use FaceDetector.FaceDetectorClassifications.{all, none}.
tracking
(optional)
booleanFlag to enable tracking of faces between frames. If true, each face will be returned with faceID attribute which should be consistent across frames.

Default: `false`

NameTypeDescription
facesFaceFeature[]Array of faces objects.
imageImage-

NameTypeDescription
bottomMouthPosition
(optional)
PointPosition of the bottom edge of the mouth in image coordinates. Returned only if detection classifications property is set to FaceDetectorLandmarks.all.
boundsFaceFeatureBoundsAn object containing face bounds.
faceID
(optional)
numberA face identifier (used for tracking, if the same face appears on consecutive frames it will have the same faceID).
leftCheekPosition
(optional)
PointPosition of the left cheek in image coordinates. Returned only if detection classifications property is set to FaceDetectorLandmarks.all.
leftEarPosition
(optional)
PointPosition of the left ear in image coordinates. Returned only if detection classifications property is set to FaceDetectorLandmarks.all.
leftEyeOpenProbability
(optional)
numberProbability that the left eye is open. Returned only if detection classifications property is set to FaceDetectorClassifications.all.
leftEyePosition
(optional)
PointPosition of the left eye in image coordinates. Returned only if detection classifications property is set to FaceDetectorLandmarks.all.
leftMouthPosition
(optional)
PointPosition of the left edge of the mouth in image coordinates. Returned only if detection classifications property is set to FaceDetectorLandmarks.all.
mouthPosition
(optional)
PointPosition of the center of the mouth in image coordinates. Returned only if detection classifications property is set to FaceDetectorLandmarks.all.
noseBasePosition
(optional)
PointPosition of the nose base in image coordinates. Returned only if detection classifications property is set to FaceDetectorLandmarks.all.
rightCheekPosition
(optional)
PointPosition of the right cheek in image coordinates. Returned only if detection classifications property is set to FaceDetectorLandmarks.all.
rightEarPosition
(optional)
PointPosition of the right ear in image coordinates. Returned only if detection classifications property is set to FaceDetectorLandmarks.all.
rightEyeOpenProbability
(optional)
numberProbability that the right eye is open. Returned only if detection classifications property is set to FaceDetectorClassifications.all.
rightEyePosition
(optional)
PointPosition of the right eye in image coordinates. Returned only if detection classifications property is set to FaceDetectorLandmarks.all.
rightMouthPosition
(optional)
PointPosition of the right edge of the mouth in image coordinates. Returned only if detection classifications property is set to FaceDetectorLandmarks.all.
rollAngle
(optional)
numberRoll angle of the face (bank).
smilingProbability
(optional)
numberProbability that the face is smiling. Returned only if detection classifications property is set to FaceDetectorClassifications.all.
yawAngle
(optional)
numberYaw angle of the face (heading, turning head left or right).

NameTypeDescription
originPointPosition of the top left corner of a square containing the face in image coordinates,
size{ height: number, width: number }Size of the square containing the face in image coordinates,

NameTypeDescription
heightnumberHeight of the image in pixels.
orientationnumberOrientation of the image (value conforms to the EXIF orientation tag standard).
uristringURI of the image.
widthnumberWidth of the image in pixels.

NameTypeDescription
xnumber-
ynumber-

  • FaceDetectorClassifications.all : "all"
  • FaceDetectorClassifications.none : "none"

  • FaceDetectorLandmarks.all : "all"
  • FaceDetectorLandmarks.none : "none"

  • FaceDetectorMode.accurate : "accurate"
  • FaceDetectorMode.fast : "fast"