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)
Creates a
FaceDetector instance from a FaceDetector.FaceDetectorOptions . |
FaceDetectorResult | |
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)
Creates a FaceDetector
instance from a FaceDetector.FaceDetectorOptions
.
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)
.
FaceDetector
supports the following color space types:
Parameters
image | a MediaPipe MPImage object for processing. |
---|---|
imageProcessingOptions | the ImageProcessingOptions specifying how to process the
input image before running inference. Note that region-of-interest is not supported
by this task: specifying ImageProcessingOptions.regionOfInterest() will result in
this method throwing an IllegalArgumentException. |
Throws
IllegalArgumentException | if the ImageProcessingOptions specify a
region-of-interest. |
---|---|
if there is an internal error. |
public 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
. Only use this method when
the FaceDetector
is created with ERROR(/RunningMode.LIVE_STREAM)
.
It's required to provide a timestamp (in milliseconds) to indicate when the input image is sent to the face detector. The input timestamps must be monotonically increasing.
FaceDetector
supports the following color space types:
Parameters
image | a MediaPipe MPImage object for processing. |
---|---|
imageProcessingOptions | the ImageProcessingOptions specifying how to process the
input image before running inference. Note that region-of-interest is not supported
by this task: specifying ImageProcessingOptions.regionOfInterest() will result in
this method throwing an IllegalArgumentException. |
timestampMs | the input timestamp (in milliseconds). |
Throws
IllegalArgumentException | if the ImageProcessingOptions specify a
region-of-interest. |
---|---|
if there is an internal error. |
public void detectAsync (MPImage image, long timestampMs)
Sends live image data to perform face detection with default image processing options, i.e.
without any rotation applied, and the results will be available via the OutputHandler.ResultListener
provided in the FaceDetector.FaceDetectorOptions
. Only use this method when the FaceDetector
is created with ERROR(/RunningMode.LIVE_STREAM)
.
It's required to provide a timestamp (in milliseconds) to indicate when the input image is sent to the face detector. The input timestamps must be monotonically increasing.
FaceDetector
supports the following color space types:
Parameters
image | a MediaPipe MPImage object for processing. |
---|---|
timestampMs | the input timestamp (in milliseconds). |
Throws
if there is an internal error. |
public FaceDetectorResult detectForVideo (MPImage image, ImageProcessingOptions imageProcessingOptions, long timestampMs)
Performs face detection on the provided video frame. Only use this method when the FaceDetector
is created with ERROR(/RunningMode.VIDEO)
.
It's required to provide the video frame's timestamp (in milliseconds). The input timestamps must be monotonically increasing.
FaceDetector
supports the following color space types:
Parameters
image | a MediaPipe MPImage object for processing. |
---|---|
imageProcessingOptions | the ImageProcessingOptions specifying how to process the
input image before running inference. Note that region-of-interest is not supported
by this task: specifying ImageProcessingOptions.regionOfInterest() will result in
this method throwing an IllegalArgumentException. |
timestampMs | the input timestamp (in milliseconds). |
Throws
IllegalArgumentException | if the ImageProcessingOptions specify a
region-of-interest. |
---|---|
if there is an internal error. |
public FaceDetectorResult detectForVideo (MPImage image, long timestampMs)
Performs face detection on the provided video frame with default image processing options, i.e.
without any rotation applied. Only use this method when the FaceDetector
is created
with ERROR(/RunningMode.VIDEO)
.
It's required to provide the video frame's timestamp (in milliseconds). The input timestamps must be monotonically increasing.
FaceDetector
supports the following color space types:
Parameters
image | a MediaPipe MPImage object for processing. |
---|---|
timestampMs | the input timestamp (in milliseconds). |
Throws
if there is an internal error. |