PoseLandmarker

public final class PoseLandmarker extends BaseVisionTaskApi


Performs pose landmarks detection on images.

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

  • Input image MPImage
    • The image that pose landmarks detection runs on.
  • Output PoseLandmarkerResult PoseLandmarkerResult
    • A PoseLandmarkerResult containing pose landmarks.

Summary

Nested types

Options for setting up an PoseLandmarker.

Builder for PoseLandmarkerOptions.

Constants

static final Set<Connection>

Public methods

static PoseLandmarker
createFromBuffer(Context context, ByteBuffer modelBuffer)

Creates a PoseLandmarker instance from a model buffer and the default PoseLandmarkerOptions.

static PoseLandmarker
createFromFile(Context context, File modelFile)

Creates a PoseLandmarker instance from a model file and the default PoseLandmarkerOptions.

static PoseLandmarker
createFromFile(Context context, String modelPath)

Creates a PoseLandmarker instance from a model file and the default PoseLandmarkerOptions.

static PoseLandmarker
createFromOptions(
    Context context,
    PoseLandmarker.PoseLandmarkerOptions landmarkerOptions
)

Creates a PoseLandmarker instance from a PoseLandmarkerOptions.

PoseLandmarkerResult
detect(MPImage image)

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

PoseLandmarkerResult
detect(MPImage image, ImageProcessingOptions imageProcessingOptions)

Performs pose landmarks detection on the provided single image.

void
detectAsync(MPImage image, long timestampMs)

Sends live image data to perform pose 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 PoseLandmarkerOptions.

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

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

PoseLandmarkerResult
detectForVideo(MPImage image, long timestampMs)

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

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

Performs pose 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

POSE_LANDMARKS

public static final Set<Connection> POSE_LANDMARKS

Public methods

createFromBuffer

public static PoseLandmarker createFromBuffer(Context context, ByteBuffer modelBuffer)

Creates a PoseLandmarker instance from a model buffer and the default PoseLandmarkerOptions.

Parameters
Context context

an Android Context.

ByteBuffer modelBuffer

a direct ByteBuffer or a MappedByteBuffer of the detection model.

Throws
com.google.mediapipe.framework.MediaPipeException

if there is an error during PoseLandmarker creation.

createFromFile

public static PoseLandmarker createFromFile(Context context, File modelFile)

Creates a PoseLandmarker instance from a model file and the default PoseLandmarkerOptions.

Parameters
Context context

an Android Context.

File modelFile

the pose landmarks model File instance.

Throws
java.io.IOException

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

com.google.mediapipe.framework.MediaPipeException

if there is an error during PoseLandmarker creation.

createFromFile

public static PoseLandmarker createFromFile(Context context, String modelPath)

Creates a PoseLandmarker instance from a model file and the default PoseLandmarkerOptions.

Parameters
Context context

an Android Context.

String modelPath

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

Throws
com.google.mediapipe.framework.MediaPipeException

if there is an error during PoseLandmarker creation.

createFromOptions

public static PoseLandmarker createFromOptions(
    Context context,
    PoseLandmarker.PoseLandmarkerOptions landmarkerOptions
)

Creates a PoseLandmarker instance from a PoseLandmarkerOptions.

Parameters
Context context

an Android Context.

PoseLandmarker.PoseLandmarkerOptions landmarkerOptions

a PoseLandmarkerOptions instance.

Throws
com.google.mediapipe.framework.MediaPipeException

if there is an error during PoseLandmarker creation.

detect

public PoseLandmarkerResult detect(MPImage image)

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

PoseLandmarker supports the following color space types:

  • Bitmap.Config.ARGB_8888
Parameters
MPImage image

a MediaPipe MPImage object for processing.

Throws
com.google.mediapipe.framework.MediaPipeException

if there is an internal error.

detect

public PoseLandmarkerResult detect(MPImage image, ImageProcessingOptions imageProcessingOptions)

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

PoseLandmarker 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.

com.google.mediapipe.framework.MediaPipeException

if there is an internal error.

detectAsync

public void detectAsync(MPImage image, long timestampMs)

Sends live image data to perform pose 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 PoseLandmarkerOptions. Only use this method when the PoseLandmarker 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 pose landmarker. The input timestamps must be monotonically increasing.

PoseLandmarker 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
com.google.mediapipe.framework.MediaPipeException

if there is an internal error.

detectAsync

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

Sends live image data to perform pose landmarks detection, and the results will be available via the ResultListener provided in the PoseLandmarkerOptions. Only use this method when the PoseLandmarker 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 pose landmarker. The input timestamps must be monotonically increasing.

PoseLandmarker 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.

com.google.mediapipe.framework.MediaPipeException

if there is an internal error.

detectForVideo

public PoseLandmarkerResult detectForVideo(MPImage image, long timestampMs)

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

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

PoseLandmarker 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
com.google.mediapipe.framework.MediaPipeException

if there is an internal error.

detectForVideo

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

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

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

PoseLandmarker 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.

com.google.mediapipe.framework.MediaPipeException

if there is an internal error.