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.
kTfLiteUInt8
/kTfLiteFloat32
)
[batch x height x width x channels]
.
batch
is required to be 1).
channels
is required to be 3).
kTfLiteFloat32
, NormalizationOptions are required to be attached
to the metadata for input normalization.
DetectionPostProcess
op, i.e:
kTfLiteFloat32
):
[1 x num_results x 4]
, the inner array representing
bounding boxes in the form [top, left, right, bottom].
BoundingBoxProperties
are required to be attached to the metadata and
must specify type=BOUNDARIES
and coordinate_type=RATIO
.
kTfLiteFloat32
):
[1 x num_results]
, each value representing the integer
index of a class.
TENSOR_VALUE_LABELS
associated files, they are used to convert the tensor values into labels.
kTfLiteFloat32
):
[1 x num_results]
, each value representing the score of
the detected object.
kTfLiteFloat32
):
[1]
.
An example of such model can be found on TensorFlow Hub..
class | ObjectDetector.ObjectDetectorOptions | Options for setting up an ObjectDetector. |
Creates an ObjectDetector
instance with a model buffer and the default ObjectDetector.ObjectDetectorOptions
.
modelBuffer | a direct ByteBuffer or a MappedByteBuffer of the detection
model |
---|
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 |
Creates an ObjectDetector
instance with a model buffer and ObjectDetector.ObjectDetectorOptions
.
modelBuffer | a direct ByteBuffer or a MappedByteBuffer of the detection
model |
---|---|
options |
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 |
Creates an ObjectDetector
instance from the default ObjectDetector.ObjectDetectorOptions
.
context | |
---|---|
modelPath | path to the detection model with metadata in the assets |
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 |
Creates an ObjectDetector
instance from the default ObjectDetector.ObjectDetectorOptions
.
modelFile | the detection model File instance |
---|
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 |
Creates an ObjectDetector
instance from ObjectDetector.ObjectDetectorOptions
.
context | |
---|---|
modelPath | path to the detection model with metadata in the assets |
options |
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 |
Creates an ObjectDetector
instance from ObjectDetector.ObjectDetectorOptions
.
modelFile | the detection model File instance |
---|---|
options |
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 |
Performs actual detection on the provided MlImage
.
image | an MlImage object that represents an image |
---|
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 |
Performs actual detection on the provided image.
ObjectDetector
supports the following TensorImage
color space types:
ObjectDetector
supports the following options:
ImageProcessingOptions.Builder.setOrientation(ImageProcessingOptions.Orientation)
). It
defaults to ImageProcessingOptions.Orientation.TOP_LEFT
.
image | a UINT8 TensorImage object that represents an RGB or YUV image |
---|---|
options | the options to configure how to preprocess the image |
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 |
Performs actual detection on the provided MlImage
with ImageProcessingOptions
.
ObjectDetector
supports the following options:
ImageProcessingOptions.Builder.setOrientation(ImageProcessingOptions.Orientation)
). It
defaults to ImageProcessingOptions.Orientation.TOP_LEFT
. MlImage.getRotation()
is not effective.
image | an MlImage object that represents an image |
---|---|
options | the options to configure how to preprocess the image |
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 |
Performs actual detection on the provided image.
ObjectDetector
supports the following TensorImage
color space types:
image | a UINT8 TensorImage object that represents an RGB or YUV image |
---|
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 |