BaseVisionTaskApi

public class BaseVisionTaskApi implements AutoCloseable

Known direct subclasses
FaceDetector

Performs face detection on images.

FaceLandmarker

Performs face landmarks detection on images.

GestureRecognizer

Performs gesture recognition on images.

HandLandmarker

Performs hand landmarks detection on images.

HolisticLandmarker

Performs holistic landmarks detection on images.

ImageClassifier

Performs classification on images.

ImageSegmenter

Performs image segmentation on images.

InteractiveSegmenterLegacy

Performs interactive segmentation on images.

ObjectDetector

Performs object detection on images.

PoseLandmarker

Performs pose landmarks detection on images.


The base class of MediaPipe vision tasks.

Summary

Constants

static final long

Public constructors

BaseVisionTaskApi(
    TaskRunner runner,
    RunningMode runningMode,
    String imageStreamName,
    String normRectStreamName
)

Constructor to initialize a BaseVisionTaskApi.

Public methods

void

Closes and cleans up the MediaPipe vision task.

static long
generateResultTimestampMs(RunningMode runningMode, Packet packet)

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

Protected methods

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

Converts an ImageProcessingOptions instance into a NormalizedRect protobuf message.

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

MICROSECONDS_PER_MILLISECOND

protected static final long MICROSECONDS_PER_MILLISECOND = 1000

Protected fields

imageStreamName

protected final String imageStreamName

normRectStreamName

protected final String normRectStreamName

runner

protected final TaskRunner runner

runningMode

protected final RunningMode runningMode

Public constructors

BaseVisionTaskApi

public BaseVisionTaskApi(
    TaskRunner runner,
    RunningMode runningMode,
    String imageStreamName,
    String normRectStreamName
)

Constructor to initialize a BaseVisionTaskApi.

Parameters
TaskRunner runner

a TaskRunner.

RunningMode runningMode

a mediapipe vision task RunningMode.

String imageStreamName

the name of the input image stream.

String normRectStreamName

the name of the input normalized rect image stream used to provide (mandatory) rotation and (optional) region-of-interest.

Public methods

close

public void close()

Closes and cleans up the MediaPipe vision task.

generateResultTimestampMs

public static long generateResultTimestampMs(RunningMode runningMode, Packet packet)

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

Parameters
RunningMode runningMode

MediaPipe Vision Tasks RunningMode.

Packet packet

the output Packet.

Protected methods

convertToNormalizedRect

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

Converts an ImageProcessingOptions instance into a NormalizedRect protobuf message.

processImageData

protected TaskResult processImageData(Map<String, Packet> inputPackets)

A synchronous method to process single image inputs. The call blocks the current thread until a failure status or a successful result is returned.

Parameters
Map<String, Packet> inputPackets

the maps of input stream names to the input packets.

Throws
com.google.mediapipe.framework.MediaPipeException

if the task is not in the image mode.

processImageData

protected TaskResult processImageData(
    MPImage image,
    ImageProcessingOptions imageProcessingOptions
)

A synchronous method to process single image inputs. The call blocks the current thread until a failure status or a successful result is returned.

Parameters
MPImage image

a MediaPipe MPImage object for processing.

ImageProcessingOptions imageProcessingOptions

the ImageProcessingOptions specifying how to process the input image before running inference.

Throws
com.google.mediapipe.framework.MediaPipeException

if the task is not in the image mode.

processVideoData

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

A synchronous method to process continuous video frames. The call blocks the current thread until a failure status or a successful result is returned.

Parameters
Map<String, Packet> inputPackets

the maps of input stream names to the input packets.

long timestampMs

the corresponding timestamp of the input image in milliseconds.

Throws
com.google.mediapipe.framework.MediaPipeException

if the task is not in the video mode.

processVideoData

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

A synchronous method to process continuous video frames. The call blocks the current thread until a failure status or a successful result is returned.

Parameters
MPImage image

a MediaPipe MPImage object for processing.

ImageProcessingOptions imageProcessingOptions

the ImageProcessingOptions specifying how to process the input image before running inference.

long timestampMs

the corresponding timestamp of the input image in milliseconds.

Throws
com.google.mediapipe.framework.MediaPipeException

if the task is not in the video mode.

sendLiveStreamData

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

An asynchronous method to send live stream data to the TaskRunner. The results will be available in the user-defined result listener.

Parameters
Map<String, Packet> inputPackets

the maps of input stream names to the input packets.

long timestampMs

the corresponding timestamp of the input image in milliseconds.

Throws
com.google.mediapipe.framework.MediaPipeException

if the task is not in the stream mode.

sendLiveStreamData

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

An asynchronous method to send live stream data to the TaskRunner. The results will be available in the user-defined result listener.

Parameters
MPImage image

a MediaPipe MPImage object for processing.

ImageProcessingOptions imageProcessingOptions

the ImageProcessingOptions specifying how to process the input image before running inference.

long timestampMs

the corresponding timestamp of the input image in milliseconds.

Throws
com.google.mediapipe.framework.MediaPipeException

if the task is not in the stream mode.