public final class ObjectDetector extends BaseVisionTaskApi

Performs object detection on images.

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

The API supports models with one image input tensor and four output tensors. To be more specific, here are the requirements.

An example of such model can be found on TensorFlow Hub..

Nested Class Summary

class ObjectDetector.ObjectDetectorOptions Options for setting up an ObjectDetector. 

Public Method Summary

static ObjectDetector
createFromBuffer(ByteBuffer modelBuffer)
Creates an ObjectDetector instance with a model buffer and the default ObjectDetector.ObjectDetectorOptions.
static ObjectDetector
static ObjectDetector
createFromFile(File modelFile)
Creates an ObjectDetector instance from the default ObjectDetector.ObjectDetectorOptions.
static ObjectDetector
createFromFile(Context context, String modelPath)
Creates an ObjectDetector instance from the default ObjectDetector.ObjectDetectorOptions.
static ObjectDetector
static ObjectDetector
List<Detection>
detect(MlImage image)
Performs actual detection on the provided MlImage.
List<Detection>
detect(TensorImage image, ImageProcessingOptions options)
Performs actual detection on the provided image.
List<Detection>
detect(MlImage image, ImageProcessingOptions options)
Performs actual detection on the provided MlImage with ImageProcessingOptions.
List<Detection>
detect(TensorImage image)
Performs actual detection on the provided image.

Protected Method Summary

void
deinit(long nativeHandle)

Inherited Method Summary

Public Methods

public static ObjectDetector createFromBuffer (ByteBuffer modelBuffer)

Creates an ObjectDetector instance with a model buffer and the default ObjectDetector.ObjectDetectorOptions.

Parameters
modelBuffer a direct ByteBuffer or a MappedByteBuffer of the detection model
Throws
IllegalArgumentException if the model buffer is not a direct ByteBuffer or a MappedByteBuffer * @throws IllegalStateException if there is an internal error
RuntimeException if there is an otherwise unspecified error

public static ObjectDetector createFromBufferAndOptions (ByteBuffer modelBuffer, ObjectDetector.ObjectDetectorOptions options)

Creates an ObjectDetector instance with a model buffer and ObjectDetector.ObjectDetectorOptions.

Parameters
modelBuffer a direct ByteBuffer or a MappedByteBuffer of the detection model
options
Throws
IllegalArgumentException if the model buffer is not a direct ByteBuffer or a MappedByteBuffer
IllegalStateException if there is an internal error
RuntimeException if there is an otherwise unspecified error

public static ObjectDetector createFromFile (File modelFile)

Creates an ObjectDetector instance from the default ObjectDetector.ObjectDetectorOptions.

Parameters
modelFile the detection model File instance
Throws
IOException if an I/O error occurs when loading the tflite model
IllegalArgumentException if an argument is invalid
IllegalStateException if there is an internal error
RuntimeException if there is an otherwise unspecified error

public static ObjectDetector createFromFile (Context context, String modelPath)

Creates an ObjectDetector instance from the default ObjectDetector.ObjectDetectorOptions.

Throws
IOException if an I/O error occurs when loading the tflite model
IllegalArgumentException if an argument is invalid
IllegalStateException if there is an internal error
RuntimeException if there is an otherwise unspecified error

public static ObjectDetector createFromFileAndOptions (File modelFile, ObjectDetector.ObjectDetectorOptions options)

Parameters
modelFile the detection model File instance
options
Throws
IOException if an I/O error occurs when loading the tflite model
IllegalArgumentException if an argument is invalid
IllegalStateException if there is an internal error
RuntimeException if there is an otherwise unspecified error

public static ObjectDetector createFromFileAndOptions (Context context, String modelPath, ObjectDetector.ObjectDetectorOptions options)

Parameters
context
modelPath path to the detection model with metadata in the assets
options
Throws
IOException if an I/O error occurs when loading the tflite model
IllegalArgumentException if an argument is invalid
IllegalStateException if there is an internal error
RuntimeException if there is an otherwise unspecified error

public List<Detection> detect (MlImage image)

Performs actual detection on the provided MlImage.

Parameters
image an MlImage object that represents an image
Throws
IllegalStateException if there is an internal error
RuntimeException if there is an otherwise unspecified error
IllegalArgumentException if the storage type or format of the image is unsupported

public List<Detection> detect (TensorImage image, ImageProcessingOptions options)

Performs actual detection on the provided image.

ObjectDetector supports the following TensorImage color space types:

ObjectDetector supports the following options:

Parameters
image a UINT8 TensorImage object that represents an RGB or YUV image
options the options to configure how to preprocess the image
Throws
IllegalStateException if there is an internal error
RuntimeException if there is an otherwise unspecified error
IllegalArgumentException if the color space type of image is unsupported

public List<Detection> detect (MlImage image, ImageProcessingOptions options)

Performs actual detection on the provided MlImage with ImageProcessingOptions.

ObjectDetector supports the following options:

Parameters
image an MlImage object that represents an image
options the options to configure how to preprocess the image
Throws
IllegalStateException if there is an internal error
RuntimeException if there is an otherwise unspecified error
IllegalArgumentException if the storage type or format of the image is unsupported

public List<Detection> detect (TensorImage image)

Performs actual detection on the provided image.

ObjectDetector supports the following TensorImage color space types:

Parameters
image a UINT8 TensorImage object that represents an RGB or YUV image
Throws
IllegalStateException if there is an internal error
RuntimeException if there is an otherwise unspecified error
IllegalArgumentException if the color space type of image is unsupported

Protected Methods

protected void deinit (long nativeHandle)