FaceStylizer

public final class FaceStylizer

Performs face stylization on images.

Note that, in addition to the standard stylization API, stylize(MPImage) and ERROR(/#stylizeForVideo), that take an input image and return the outputs, but involves deep copy of the returns, FaceStylizer also supports the callback API, stylizeWithResultListener(MPImage) and ERROR(/#stylizeForVideoWithResultListener), which allow you to access the outputs through zero copy for the duration of the result listener.

The callback API is available for all RunningMode in FaceStylizer. Set OutputHandler.ResultListener in FaceStylizer.FaceStylizerOptions properly to use the callback API.

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

  • Input image MPImage
    • The image that face stylizer runs on.
  • Output MPImage MPImage
    • A MPImage containing a stylized face.

Nested Classes

class FaceStylizer.FaceStylizerOptions Options for setting up an FaceStylizer

Public Methods

static FaceStylizer
createFromOptions(Context context, FaceStylizer.FaceStylizerOptions stylizerOptions)
Creates an FaceStylizer instance from an FaceStylizer.FaceStylizerOptions.
FaceStylizerResult
stylize(MPImage image, ImageProcessingOptions imageProcessingOptions)
Performs face stylization on the provided single image.
FaceStylizerResult
stylize(MPImage image)
Performs face stylization on the provided single image with default image processing options, i.e.
void
stylizeWithResultListener(MPImage image)
Performs face stylization on the provided single image with default image processing options, i.e.
void
stylizeWithResultListener(MPImage image, ImageProcessingOptions imageProcessingOptions)
Performs face stylization on the provided single image, and provides zero-copied results via OutputHandler.ResultListener in FaceStylizer.FaceStylizerOptions.

Inherited Methods

Public Methods

public static FaceStylizer createFromOptions (Context context, FaceStylizer.FaceStylizerOptions stylizerOptions)

Creates an FaceStylizer instance from an FaceStylizer.FaceStylizerOptions.

Parameters
context an Android ERROR(/Context).
stylizerOptions an FaceStylizer.FaceStylizerOptions instance.
Throws
if there is an error during FaceStylizer creation.

public FaceStylizerResult stylize (MPImage image, ImageProcessingOptions imageProcessingOptions)

Performs face stylization on the provided single image. Only use this method when the FaceStylizer is created with RunningMode.IMAGE.

FaceStylizer supports the following color space types:

The input image can be of any size. The output image is the stylized image with the most visible face. The stylized output image size is the same as the model output size. When no face is detected on the input image, returns Optional.empty().

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. Or if FaceStylizer is created with a OutputHandler.ResultListener.

public FaceStylizerResult stylize (MPImage image)

Performs face stylization on the provided single image with default image processing options, i.e. without any rotation applied. Only use this method when the FaceStylizer is created with RunningMode.IMAGE.

FaceStylizer supports the following color space types:

The input image can be of any size. The output image is the stylized image with the most visible face. The stylized output image size is the same as the model output size. When no face is detected on the input image, returns Optional.empty().

Parameters
image a MediaPipe MPImage object for processing.
Throws
if there is an internal error. Or if FaceStylizer is created with a OutputHandler.ResultListener.

public void stylizeWithResultListener (MPImage image)

Performs face stylization on the provided single image with default image processing options, i.e. without any rotation applied, and provides zero-copied results via OutputHandler.ResultListener in FaceStylizer.FaceStylizerOptions. Only use this method when the FaceStylizer is created with RunningMode.IMAGE.

FaceStylizer supports the following color space types:

The input image can be of any size. The output image is the stylized image with the most visible face. The stylized output image size is the same as the model output size. When no face is detected on the input image, returns Optional.empty().

Parameters
image a MediaPipe MPImage object for processing.
Throws
IllegalArgumentException if the ImageProcessingOptions specify a region-of-interest.
if there is an internal error. Or if FaceStylizer is not created with OutputHandler.ResultListener set in FaceStylizer.FaceStylizerOptions.

public void stylizeWithResultListener (MPImage image, ImageProcessingOptions imageProcessingOptions)

Performs face stylization on the provided single image, and provides zero-copied results via OutputHandler.ResultListener in FaceStylizer.FaceStylizerOptions. Only use this method when the FaceStylizer is created with RunningMode.IMAGE.

FaceStylizer supports the following color space types:

The input image can be of any size. The output image is the stylized image with the most visible face. The stylized output image size is the same as the model output size. When no face is detected on the input image, returns Optional.empty().

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. Or if FaceStylizer is not created with OutputHandler.ResultListener set in FaceStylizer.FaceStylizerOptions.