FaceDetector

public interface FaceDetector extends Detector<List<Face>>, OptionalModuleApi

A FaceDetection client for finding Faces in a supplied image.

A FaceDetector is created via FaceDetection.getClient(FaceDetectorOptions) or FaceDetection.getClient(), if you wish to use the default options. For example, the code below creates a face detector client with default options.

FaceDetector faceDetector = FaceDetection.getClient();
 
To perform face detection in an image, you first need to create an instance of InputImage from a Bitmap, ByteBuffer, Image etc. See InputImage documentation for more details. For example, the code below creates an InputImage from a Bitmap.
InputImage image = InputImage.fromBitmap(bitmap, rotationDegrees);
 
Then the code below can detect faces in the supplied InputImage.
Task<List<Face>> task = faceDetector.process(image);
 task.addOnSuccessListener(...).addOnFailureListener(...);
 

Public Method Summary

abstract void
close()
Closes the detector and releases its resources.
abstract Task<List<Face>>
process(MlImage image)
Detects human faces from the supplied image.
abstract Task<List<Face>>
process(InputImage image)
Detects human faces from the supplied image.

Inherited Method Summary

Public Methods

public abstract void close ()

Closes the detector and releases its resources.

public abstract Task<List<Face>> process (MlImage image)

Detects human faces from the supplied image.

This is an experimental API in beta version.

Create an MlImage object using one of MlImage's builder methods. See MlImage documentation for more details.

Note that the width of the provided image cannot be less than 32 if FaceDetectorOptions.CONTOUR_MODE_ALL is specified.

If the face detection model has not been downloaded yet when you are depending on com.google.android.gms:play-services-mlkit-face-detection, the returned Task will contain an MlKitException with error code MlKitException.UNAVAILABLE.

If there is no face gets detected, the returned Task will contain an empty List.

Returns
  • a Task that asynchronously returns a List of detected Faces

public abstract Task<List<Face>> process (InputImage image)

Detects human faces from the supplied image.

Create an InputImage object using one of InputImage's factory methods. See InputImage documentation for more details.

Note that the width of the provided image cannot be less than 32 if FaceDetectorOptions.CONTOUR_MODE_ALL is specified.

If the face detection model has not been downloaded yet when you are depending on com.google.android.gms:play-services-mlkit-face-detection, the returned Task will contain an MlKitException with error code MlKitException.UNAVAILABLE.

If there is no face gets detected, the returned Task will contain an empty List.

Returns
  • a Task that asynchronously returns a List of detected Faces