ImageAnalysis.Builder

public static final class ImageAnalysis.Builder
extends Object implements ExtendableBuilder<T extends UseCase>

java.lang.Object
   ↳ androidx.camera.core.ImageAnalysis.Builder


Builder for a ImageAnalysis.

Summary

Public constructors

Builder()

Creates a new Builder object.

Public methods

ImageAnalysis build()

Builds an ImageAnalysis from the current state.

ImageAnalysis.Builder setBackgroundExecutor(Executor executor)

Sets the default executor that will be used for background tasks.

ImageAnalysis.Builder setBackpressureStrategy(int strategy)

Sets the backpressure strategy to apply to the image producer to deal with scenarios where images may be produced faster than they can be analyzed.

ImageAnalysis.Builder setImageQueueDepth(int depth)

Sets the number of images available to the camera pipeline for ImageAnalysis.STRATEGY_BLOCK_PRODUCER mode.

ImageAnalysis.Builder setOutputImageFormat(int outputImageFormat)

Sets output image format.

ImageAnalysis.Builder setTargetAspectRatio(int aspectRatio)

Sets the aspect ratio of the intended target for images from this configuration.

ImageAnalysis.Builder setTargetName(String targetName)

Sets the name of the target object being configured, used only for debug logging.

ImageAnalysis.Builder setTargetResolution(Size resolution)

Sets the resolution of the intended target from this configuration.

ImageAnalysis.Builder setTargetRotation(int rotation)

Sets the rotation of the intended target for images from this configuration.

Inherited methods

Public constructors

Builder

public Builder ()

Creates a new Builder object.

Public methods

build

public ImageAnalysis build ()

Builds an ImageAnalysis from the current state.

Returns
ImageAnalysis A ImageAnalysis populated with the current state.

Throws
IllegalArgumentException if attempting to set both target aspect ratio and target resolution.

setBackgroundExecutor

public ImageAnalysis.Builder setBackgroundExecutor (Executor executor)

Sets the default executor that will be used for background tasks.

If not set, the background executor will default to an automatically generated Executor.

Parameters
executor Executor: The executor which will be used for background tasks.

Returns
ImageAnalysis.Builder the current Builder.

setBackpressureStrategy

public ImageAnalysis.Builder setBackpressureStrategy (int strategy)

Sets the backpressure strategy to apply to the image producer to deal with scenarios where images may be produced faster than they can be analyzed.

The available values are ImageAnalysis.STRATEGY_BLOCK_PRODUCER and ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST.

If not set, the backpressure strategy will default to ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST.

Parameters
strategy int: The strategy to use.

Returns
ImageAnalysis.Builder The current Builder.

setImageQueueDepth

public ImageAnalysis.Builder setImageQueueDepth (int depth)

Sets the number of images available to the camera pipeline for ImageAnalysis.STRATEGY_BLOCK_PRODUCER mode.

The image queue depth is the number of images available to the camera to fill with data. This includes the image currently being analyzed by ImageAnalysis.Analyzer.analyze(ImageProxy). Increasing the image queue depth may make camera operation smoother, depending on the backpressure strategy, at the cost of increased memory usage.

When the backpressure strategy is set to ImageAnalysis.STRATEGY_BLOCK_PRODUCER, increasing the image queue depth may make the camera pipeline run smoother on systems under high load. However, the time spent analyzing an image should still be kept under a single frame period for the current frame rate, on average, to avoid stalling the camera pipeline.

The value only applies to ImageAnalysis.STRATEGY_BLOCK_PRODUCER mode. For ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST the value is ignored.

If not set, and this option is used by the selected backpressure strategy, the default will be a queue depth of 6 images.

Parameters
depth int: The total number of images available to the camera.

Returns
ImageAnalysis.Builder The cu