FaceDetector

public interface FaceDetector implements Closeable LifecycleObserver

A FaceDetection client for finding Faces in a supplied image.

A FaceDetector is created via getClient(FaceDetectorOptions) or 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(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 (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 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 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