ObjectDetector.ObjectDetectorOptions.Builder

public abstract class ObjectDetector.ObjectDetectorOptions.Builder


Builder for ObjectDetectorOptions.

Summary

Public constructors

Public methods

final ObjectDetector.ObjectDetectorOptions

Validates and builds the ObjectDetectorOptions instance.

abstract ObjectDetector.ObjectDetectorOptions.Builder

Sets the BaseOptions for the object detector task.

abstract ObjectDetector.ObjectDetectorOptions.Builder

Sets the optional allowlist of category names.

abstract ObjectDetector.ObjectDetectorOptions.Builder

Sets the optional denylist of category names.

abstract ObjectDetector.ObjectDetectorOptions.Builder

Sets the optional locale to use for display names specified through the TFLite Model Metadata, if any.

abstract ObjectDetector.ObjectDetectorOptions.Builder

Sets an optional ErrorListener}.

abstract ObjectDetector.ObjectDetectorOptions.Builder

Sets the optional maximum number of top-scored detection results to return.

abstract ObjectDetector.ObjectDetectorOptions.Builder

Sets the ResultListener to receive the detection results asynchronously when the object detector is in the live stream mode.

abstract ObjectDetector.ObjectDetectorOptions.Builder

Sets the RunningMode for the object detector task.

abstract ObjectDetector.ObjectDetectorOptions.Builder

Sets the optional score threshold that overrides the one provided in the model metadata (if any).

Public constructors

Builder

public Builder()

Public methods

build

public final ObjectDetector.ObjectDetectorOptions build()

Validates and builds the ObjectDetectorOptions instance.

Throws
java.lang.IllegalArgumentException

if the result listener and the running mode are not properly configured. The result listener should only be set when the object detector is in the live stream mode.

setBaseOptions

public abstract ObjectDetector.ObjectDetectorOptions.Builder setBaseOptions(BaseOptions value)

Sets the BaseOptions for the object detector task.

setCategoryAllowlist

public abstract ObjectDetector.ObjectDetectorOptions.Builder setCategoryAllowlist(List<String> value)

Sets the optional allowlist of category names.

If non-empty, detection results whose category name is not in this set will be filtered out. Duplicate or unknown category names are ignored. Mutually exclusive with categoryDenylist.

setCategoryDenylist

public abstract ObjectDetector.ObjectDetectorOptions.Builder setCategoryDenylist(List<String> value)

Sets the optional denylist of category names.

If non-empty, detection results whose category name is in this set will be filtered out. Duplicate or unknown category names are ignored. Mutually exclusive with categoryAllowlist.

setDisplayNamesLocale

public abstract ObjectDetector.ObjectDetectorOptions.Builder setDisplayNamesLocale(String value)

Sets the optional locale to use for display names specified through the TFLite Model Metadata, if any.

setErrorListener

public abstract ObjectDetector.ObjectDetectorOptions.Builder setErrorListener(ErrorListener value)

Sets an optional ErrorListener}.

setMaxResults

public abstract ObjectDetector.ObjectDetectorOptions.Builder setMaxResults(Integer value)

Sets the optional maximum number of top-scored detection results to return.

Overrides the ones provided in the model metadata. Results below this value are rejected.

setResultListener

public abstract ObjectDetector.ObjectDetectorOptions.Builder setResultListener(
    OutputHandler.ResultListener<ObjectDetectorResult, MPImage> value
)

Sets the ResultListener to receive the detection results asynchronously when the object detector is in the live stream mode.

setRunningMode

public abstract ObjectDetector.ObjectDetectorOptions.Builder setRunningMode(RunningMode value)

Sets the RunningMode for the object detector task. Default to the image mode. Object detector has three modes:

  • IMAGE: The mode for detecting objects on single image inputs.
  • VIDEO: The mode for detecting objects on the decoded frames of a video.
  • LIVE_STREAM: The mode for for detecting objects on a live stream of input data, such as from camera. In this mode, setResultListener must be called to set up a listener to receive the detection results asynchronously.

setScoreThreshold

public abstract ObjectDetector.ObjectDetectorOptions.Builder setScoreThreshold(Float value)

Sets the optional score threshold that overrides the one provided in the model metadata (if any). Results below this value are rejected.