FaceDetector

public final class FaceDetector

Performs face detection on images.

The API expects a TFLite model with TFLite Model Metadata..

  • Input image MPImage
    • The image that the face detector runs on.
  • Output FaceDetectorResult FaceDetectorResult
    • A FaceDetectorResult containing detected faces.

Nested Classes

class FaceDetector.FaceDetectorOptions Options for setting up a FaceDetector

Public Methods

static FaceDetector
createFromBuffer(Context context, ByteBuffer modelBuffer)
Creates a FaceDetector instance from a model buffer and the default FaceDetector.FaceDetectorOptions.
static FaceDetector
createFromFile(Context context, String modelPath)
Creates a FaceDetector instance from a model file and the default FaceDetector.FaceDetectorOptions.
static FaceDetector
createFromFile(Context context, File modelFile)
Creates a FaceDetector instance from a model file and the default FaceDetector.FaceDetectorOptions.
static FaceDetector
createFromOptions(Context context, FaceDetector.FaceDetectorOptions detectorOptions)
FaceDetectorResult
detect(MPImage image)
Performs face detection on the provided single image with default image processing options, i.e.
FaceDetectorResult
detect(MPImage image, ImageProcessingOptions imageProcessingOptions)
Performs face detection on the provided single image.
void
detectAsync(MPImage image, ImageProcessingOptions imageProcessingOptions, long timestampMs)
Sends live image data to perform face detection, and the results will be available via the OutputHandler.ResultListener provided in the FaceDetector.FaceDetectorOptions.
void
detectAsync(MPImage image, long timestampMs)
Sends live image data to perform face detection with default image processing options, i.e.
FaceDetectorResult
detectForVideo(MPImage image, ImageProcessingOptions imageProcessingOptions, long timestampMs)
Performs face detection on the provided video frame.
FaceDetectorResult
detectForVideo(MPImage image, long timestampMs)
Performs face detection on the provided video frame with default image processing options, i.e.

Inherited Methods

Public Methods

public static FaceDetector createFromBuffer (Context context, ByteBuffer modelBuffer)

Creates a FaceDetector instance from a model buffer and the default FaceDetector.FaceDetectorOptions.

Parameters
context an Android ERROR(/Context).
modelBuffer a direct ByteBuffer or a ERROR(/MappedByteBuffer) of the detection model.
Throws
if there is an error during FaceDetector creation.

public static FaceDetector createFromFile (Context context, String modelPath)

Creates a FaceDetector instance from a model file and the default FaceDetector.FaceDetectorOptions.

Parameters
context an Android ERROR(/Context).
modelPath path to the detection model with metadata in the assets.
Throws
if there is an error during FaceDetector creation.

public static FaceDetector createFromFile (Context context, File modelFile)

Creates a FaceDetector instance from a model file and the default FaceDetector.FaceDetectorOptions.

Parameters
context an Android ERROR(/Context).
modelFile the detection model File instance.
Throws
IOException if an I/O error occurs when opening the tflite model file.
if there is an error during FaceDetector creation.

public static FaceDetector createFromOptions (Context context, FaceDetector.FaceDetectorOptions detectorOptions)

Parameters
context an Android ERROR(/Context).
detectorOptions a FaceDetector.FaceDetectorOptions instance.
Throws
if there is an error during FaceDetector creation.

public FaceDetectorResult detect (MPImage image)

Performs face detection on the provided single image with default image processing options, i.e. without any rotation applied. Only use this method when the FaceDetector is created with ERROR(/RunningMode.IMAGE).

FaceDetector supports the following color space types:

Parameters
image a MediaPipe MPImage object for processing.
Throws
if there is an internal error.

public FaceDetectorResult detect (MPImage image, ImageProcessingOptions imageProcessingOptions)

Performs face detection on the provided single image. Only use this method when the FaceDetector is created with ERROR(/RunningMode.IMAGE).