FaceLandmarker

public final class FaceLandmarker extends BaseVisionTaskApi


Performs face landmarks detection on images.

This API expects a pre-trained face landmarks model asset bundle. See .

  • Input image MPImage
    • The image that face landmarks detection runs on.
  • Output FaceLandmarkerResult
    • A FaceLandmarkerResult containing face landmarks.

Summary

Nested types

Options for setting up an FaceLandmarker.

Builder for FaceLandmarkerOptions.

Public methods

static FaceLandmarker
createFromBuffer(Context context, ByteBuffer modelAssetBuffer)

Creates a FaceLandmarker instance from a model asset bundle buffer and the default FaceLandmarkerOptions.

static FaceLandmarker
createFromFile(Context context, File modelAssetFile)

Creates a FaceLandmarker instance from a model asset bundle file and the default FaceLandmarkerOptions.

static FaceLandmarker
createFromFile(Context context, String modelAssetPath)

Creates a FaceLandmarker instance from a model asset bundle path and the default FaceLandmarkerOptions.

static FaceLandmarker
createFromOptions(
    Context context,
    FaceLandmarker.FaceLandmarkerOptions landmarkerOptions
)

Creates a FaceLandmarker instance from a FaceLandmarkerOptions.

FaceLandmarkerResult
detect(MPImage image)

Performs face landmarks detection on the provided single image with default image processing options, i.e. without any rotation applied.

FaceLandmarkerResult
detect(MPImage image, ImageProcessingOptions imageProcessingOptions)

Performs face landmarks detection on the provided single image.

void
detectAsync(MPImage image, long timestampMs)

Sends live image data to perform face landmarks detection with default image processing options, i.e. without any rotation applied, and the results will be available via the ResultListener provided in the FaceLandmarkerOptions.

void
detectAsync(
    MPImage image,
    ImageProcessingOptions imageProcessingOptions,
    long timestampMs
)

Sends live image data to perform face landmarks detection, and the results will be available via the ResultListener provided in the FaceLandmarkerOptions.

FaceLandmarkerResult
detectForVideo(MPImage image, long timestampMs)

Performs face landmarks detection on the provided video frame with default image processing options, i.e. without any rotation applied.

FaceLandmarkerResult
detectForVideo(
    MPImage image,
    ImageProcessingOptions imageProcessingOptions,
    long timestampMs
)

Performs face landmarks detection on the provided video frame.

Inherited methods

From java.lang.AutoCloseable
abstract void
From com.google.mediapipe.tasks.vision.core.BaseVisionTaskApi
void

Closes and cleans up the MediaPipe vision task.

static RectProto.NormalizedRect
convertToNormalizedRect(
    ImageProcessingOptions imageProcessingOptions,
    MPImage image
)

Converts an ImageProcessingOptions instance into a NormalizedRect protobuf message.

static long

Generates the timestamp of a vision task result object from the vision task running mode and the output packet.

TaskResult
processImageData(Map<String, Packet> inputPackets)

A synchronous method to process single image inputs.

TaskResult
processImageData(
    MPImage image,
    ImageProcessingOptions imageProcessingOptions
)

A synchronous method to process single image inputs.

TaskResult
processVideoData(Map<String, Packet> inputPackets, long timestampMs)

A synchronous method to process continuous video frames.

TaskResult
processVideoData(
    MPImage image,
    ImageProcessingOptions imageProcessingOptions,
    long timestampMs
)

A synchronous method to process continuous video frames.

void
sendLiveStreamData(Map<String, Packet> inputPackets, long timestampMs)

An asynchronous method to send live stream data to the TaskRunner.

void
sendLiveStreamData(
    MPImage image,
    ImageProcessingOptions imageProcessingOptions,
    long timestampMs
)

An asynchronous method to send live stream data to the TaskRunner.

Constants

FACE_LANDMARKS_CONNECTORS

public static final Set<Connection> FACE_LANDMARKS_CONNECTORS

FACE_LANDMARKS_FACE_OVAL

public static final Set<Connection> FACE_LANDMARKS_FACE_OVAL

FACE_LANDMARKS_LEFT_EYE

public static final Set<Connection> FACE_LANDMARKS_LEFT_EYE

FACE_LANDMARKS_LEFT_EYE_BROW

public static final Set<Connection> FACE_LANDMARKS_LEFT_EYE_BROW

FACE_LANDMARKS_LEFT_IRIS

public static final Set<Connection> FACE_LANDMARKS_LEFT_IRIS

FACE_LANDMARKS_LIPS

public static final Set<Connection> FACE_LANDMARKS_LIPS

FACE_LANDMARKS_RIGHT_EYE

public static final Set<Connection> FACE_LANDMARKS_RIGHT_EYE

FACE_LANDMARKS_RIGHT_EYE_BROW

public static final Set<Connection> FACE_LANDMARKS_RIGHT_EYE_BROW

FACE_LANDMARKS_RIGHT_IRIS

public static final Set<Connection> FACE_LANDMARKS_RIGHT_IRIS

FACE_LANDMARKS_TESSELATION

public static final Set<Connection> FACE_LANDMARKS_TESSELATION

Public methods

createFromBuffer

public static FaceLandmarker createFromBuffer(Context context, ByteBuffer modelAssetBuffer)

Creates a FaceLandmarker instance from a model asset bundle buffer and the default FaceLandmarkerOptions.

Parameters
Context context

an Android Context.

ByteBuffer modelAssetBuffer

a direct ByteBuffer or a MappedByteBuffer of the detection model.

Throws
MediaPipeException

if there is an error during FaceLandmarker creation.

createFromFile

public static FaceLandmarker createFromFile(Context context, File modelAssetFile)

Creates a FaceLandmarker instance from a model asset bundle file and the default FaceLandmarkerOptions.

Parameters
Context context

an Android Context.

File modelAssetFile

the face landmarks model File instance.

Throws
java.io.IOException

if an I/O error occurs when opening the tflite model file.

MediaPipeException

if there is an error during FaceLandmarker creation.

createFromFile

public static FaceLandmarker createFromFile(Context context, String modelAssetPath)

Creates a FaceLandmarker instance from a model asset bundle path and the default FaceLandmarkerOptions.

Parameters
Context context

an Android Context.

String modelAssetPath

path to the face landmarks model with metadata in the assets.

Throws
MediaPipeException

if there is an error during FaceLandmarker creation.

createFromOptions

public static FaceLandmarker createFromOptions(
    Context context,
    FaceLandmarker.FaceLandmarkerOptions landmarkerOptions
)

Creates a FaceLandmarker instance from a FaceLandmarkerOptions.

Parameters
Context context

an Android Context.

FaceLandmarker.FaceLandmarkerOptions landmarkerOptions

a FaceLandmarkerOptions instance.

Throws
MediaPipeException

if there is an error during FaceLandmarker creation.

detect

public FaceLandmarkerResult detect(MPImage image)

Performs face landmarks detection on the provided single image with default image processing options, i.e. without any rotation applied. Only use this method when the FaceLandmarker is created with RunningMode.IMAGE. TODO update java doc for input image format.

FaceLandmarker supports the following color space types:

  • Bitmap.Config.ARGB_8888
Parameters
MPImage image

a MediaPipe MPImage object for processing.

Throws
MediaPipeException

if there is an internal error.

detect

public FaceLandmarkerResult detect(MPImage image, ImageProcessingOptions imageProcessingOptions)

Performs face landmarks detection on the provided single image. Only use this method when the FaceLandmarker is created with RunningMode.IMAGE. TODO update java doc for input image format.

FaceLandmarker supports the following color space types:

  • Bitmap.Config.ARGB_8888
Parameters
MPImage image

a MediaPipe MPImage object for processing.

ImageProcessingOptions 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 regionOfInterest will result in this method throwing an IllegalArgumentException.

Throws
java.lang.IllegalArgumentException

if the ImageProcessingOptions specify a region-of-interest.

MediaPipeException

if there is an internal error.

detectAsync

public void detectAsync(MPImage image, long timestampMs)

Sends live image data to perform face landmarks detection with default image processing options, i.e. without any rotation applied, and the results will be available via the ResultListener provided in the FaceLandmarkerOptions. Only use this method when the FaceLandmarker is created with RunningMode.LIVE_STREAM.

It's required to provide a timestamp (in milliseconds) to indicate when the input image is sent to the face landmarker. The input timestamps must be monotonically increasing.

FaceLandmarker supports the following color space types:

  • Bitmap.Config.ARGB_8888
Parameters
MPImage image

a MediaPipe MPImage object for processing.

long timestampMs

the input timestamp (in milliseconds).

Throws
MediaPipeException

if there is an internal error.

detectAsync

public void detectAsync(
    MPImage image,
    ImageProcessingOptions imageProcessingOptions,
    long timestampMs
)

Sends live image data to perform face landmarks detection, and the results will be available via the ResultListener provided in the FaceLandmarkerOptions. Only use this method when the FaceLandmarker is created with RunningMode.LIVE_STREAM.

It's required to provide a timestamp (in milliseconds) to indicate when the input image is sent to the face landmarker. The input timestamps must be monotonically increasing.

FaceLandmarker supports the following color space types:

  • Bitmap.Config.ARGB_8888
Parameters
MPImage image

a MediaPipe MPImage object for processing.

ImageProcessingOptions 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 regionOfInterest will result in this method throwing an IllegalArgumentException.

long timestampMs

the input timestamp (in milliseconds).

Throws
java.lang.IllegalArgumentException

if the ImageProcessingOptions specify a region-of-interest.

MediaPipeException

if there is an internal error.

detectForVideo

public FaceLandmarkerResult detectForVideo(MPImage image, long timestampMs)

Performs face landmarks detection on the provided video frame with default image processing options, i.e. without any rotation applied. Only use this method when the FaceLandmarker is created with RunningMode.VIDEO.

It's required to provide the video frame's timestamp (in milliseconds). The input timestamps must be monotonically increasing.

FaceLandmarker supports the following color space types:

  • Bitmap.Config.ARGB_8888
Parameters
MPImage image

a MediaPipe MPImage object for processing.

long timestampMs

the input timestamp (in milliseconds).

Throws
MediaPipeException

if there is an internal error.

detectForVideo

public FaceLandmarkerResult detectForVideo(
    MPImage image,
    ImageProcessingOptions imageProcessingOptions,
    long timestampMs
)

Performs face landmarks detection on the provided video frame. Only use this method when the FaceLandmarker is created with RunningMode.VIDEO.

It's required to provide the video frame's timestamp (in milliseconds). The input timestamps must be monotonically increasing.

FaceLandmarker supports the following color space types:

  • Bitmap.Config.ARGB_8888
Parameters
MPImage image

a MediaPipe MPImage object for processing.

ImageProcessingOptions 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 regionOfInterest will result in this method throwing an IllegalArgumentException.

long timestampMs

the input timestamp (in milliseconds).

Throws
java.lang.IllegalArgumentException

if the ImageProcessingOptions specify a region-of-interest.

MediaPipeException

if there is an internal error.