ObjectDetector.ObjectDetectorOptions.Builder

public static abstract class ObjectDetector.ObjectDetectorOptions.Builder

Public Constructors

Public Methods

final ObjectDetector.ObjectDetectorOptions
build()
Validates and builds the ObjectDetector.ObjectDetectorOptions instance.
abstract ObjectDetector.ObjectDetectorOptions.Builder
setBaseOptions(BaseOptions value)
Sets the BaseOptions for the object detector task.
abstract ObjectDetector.ObjectDetectorOptions.Builder
setCategoryAllowlist(List<String> value)
Sets the optional allowlist of category names.
abstract ObjectDetector.ObjectDetectorOptions.Builder
setCategoryDenylist(List<String> value)
Sets the optional denylist of category names.
abstract ObjectDetector.ObjectDetectorOptions.Builder
setDisplayNamesLocale(String value)
Sets the optional locale to use for display names specified through the TFLite Model Metadata, if any.
abstract ObjectDetector.ObjectDetectorOptions.Builder
setErrorListener(ErrorListener value)
Sets an optional ErrorListener}.
abstract ObjectDetector.ObjectDetectorOptions.Builder
setMaxResults(Integer value)
Sets the optional maximum number of top-scored detection results to return.
abstract ObjectDetector.ObjectDetectorOptions.Builder
setResultListener(ResultListener<ObjectDetectorResultMPImage> value)
Sets the OutputHandler.ResultListener to receive the detection results asynchronously when the object detector is in the live stream mode.
abstract ObjectDetector.ObjectDetectorOptions.Builder
setRunningMode(RunningMode value)
Sets the RunningMode for the object detector task.
abstract ObjectDetector.ObjectDetectorOptions.Builder
setScoreThreshold(Float value)
Sets the optional score threshold that overrides the one provided in the model metadata (if any).

Inherited Methods

Public Constructors

public Builder ()

Public Methods

public final ObjectDetector.ObjectDetectorOptions build ()

Validates and builds the ObjectDetector.ObjectDetectorOptions instance.

Throws
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.

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

Sets the BaseOptions for the object detector task.

Parameters
value

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.

Parameters
value

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.

Parameters
value

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.

Parameters
value

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

Sets an optional ErrorListener}.

Parameters
value

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.

Parameters
value

public abstract ObjectDetector.ObjectDetectorOptions.Builder setResultListener (ResultListener<ObjectDetectorResultMPImage> value)

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

Parameters
value

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.