ImageAnalysisConfig.Builder

public static final class ImageAnalysisConfig.Builder
extends Object implements Config.ExtendableBuilder, Builder<ImageAnalysisConfig.Builder>

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


Builder for a ImageAnalysisConfig.

Summary

Public constructors

ImageAnalysisConfig.Builder()

Creates a new Builder object.

Public methods

ImageAnalysisConfig build()

Builds an immutable ImageAnalysisConfig from the current state.

static ImageAnalysisConfig.Builder fromConfig(ImageAnalysisConfig configuration)

Generates a Builder from another Config object.

ImageAnalysisConfig.Builder setCallbackHandler(Handler handler)

Sets the default handler that will be used for callbacks.

ImageAnalysisConfig.Builder setImageQueueDepth(int depth)

Sets the number of images available to the camera pipeline.

ImageAnalysisConfig.Builder setImageReaderMode(ImageAnalysis.ImageReaderMode mode)

Sets the mode that the image is acquired from ImageReader.

ImageAnalysisConfig.Builder setLensFacing(CameraX.LensFacing lensFacing)

Sets the primary camera to be configured based on the direction the lens is facing.

ImageAnalysisConfig.Builder setTargetAspectRatio(Rational aspectRatio)

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

ImageAnalysisConfig.Builder setTargetName(String targetName)

Sets the name of the target object being configured.

ImageAnalysisConfig.Builder setTargetResolution(Size resolution)

Sets the resolution of the intended target from this configuration.

ImageAnalysisConfig.Builder setTargetRotation(int rotation)

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

Inherited methods

Public constructors

ImageAnalysisConfig.Builder

public ImageAnalysisConfig.Builder ()

Creates a new Builder object.

Public methods

build

public ImageAnalysisConfig build ()

Builds an immutable ImageAnalysisConfig from the current state.

Returns
ImageAnalysisConfig A ImageAnalysisConfig populated with the current state.

fromConfig

public static ImageAnalysisConfig.Builder fromConfig (ImageAnalysisConfig configuration)

Generates a Builder from another Config object.

Parameters
configuration ImageAnalysisConfig: An immutable configuration to pre-populate this builder.

Returns
ImageAnalysisConfig.Builder The new Builder.

setCallbackHandler

public ImageAnalysisConfig.Builder setCallbackHandler (Handler handler)

Sets the default handler that will be used for callbacks.

Parameters
handler Handler: The handler which will be used to post callbacks.

Returns
ImageAnalysisConfig.Builder the current Builder.

setImageQueueDepth

public ImageAnalysisConfig.Builder setImageQueueDepth (int depth)

Sets the number of images available to the camera pipeline.

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, int). Increasing the image queue depth may make camera operation smoother, depending on the ImageAnalysis.ImageReaderMode, at the cost of increased memory usage.

When the ImageAnalysis.ImageReaderMode is set to ImageAnalysis.ImageReaderMode.ACQUIRE_LATEST_IMAGE, increasing the image queue depth will increase the amount of time available to analyze an image before stalling the capture pipeline.

When the ImageAnalysis.ImageReaderMode is set to ImageAnalysis.ImageReaderMode.ACQUIRE_NEXT_IMAGE, 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.

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

Returns
ImageAnalysisConfig.Builder The current Builder.

setImageReaderMode

public ImageAnalysisConfig.Builder setImageReaderMode (ImageAnalysis.ImageReaderMode mode)

Sets the mode that the image is acquired from ImageReader.

The available values are ImageAnalysis.ImageReaderMode.ACQUIRE_NEXT_IMAGE and ImageAnalysis.ImageReaderMode.ACQUIRE_LATEST_IMAGE.

Parameters
mode ImageAnalysis.ImageReaderMode: The mode to set.

Returns
ImageAnalysisConfig.Builder The current Builder.

setLensFacing

public ImageAnalysisConfig.Builder setLensFacing (CameraX.LensFacing lensFacing)

Sets the primary camera to be configured based on the direction the lens is facing.

If multiple cameras exist with equivalent lens facing direction, the first ("primary") camera for that direction will be chosen.

Parameters
lensFacing CameraX.LensFacing: The direction of the camera's lens.

Returns
ImageAnalysisConfig.Builder the current Builder.

setTargetAspectRatio

public ImageAnalysisConfig.Builder setTargetAspectRatio (Rational aspectRatio)

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

This is the ratio of the target's width to the image's height, where the numerator of the provided Rational corresponds to the width, and the denominator corresponds to the height.

Parameters
aspectRatio Rational: A Rational representing the ratio of the target's width and height.

Returns
ImageAnalysisConfig.Builder The current Builder.

setTargetName

public ImageAnalysisConfig.Builder setTargetName (String targetName)

Sets the name of the target object being configured.

The name should be a value that can uniquely identify an instance of the object being configured.

Parameters
targetName String: A unique string identifier for the instance of the class being configured.

Returns
ImageAnalysisConfig.Builder the current Builder.

setTargetResolution

public ImageAnalysisConfig.Builder setTargetResolution (Size resolution)

Sets the resolution of the intended target from this configuration.

The target resolution attempts to establish a minimum bound for the image resolution. The actual image resolution will be the closest available resolution in size that is not smaller than the target resolution, as determined by the Camera implementation. However, if no resolution exists that is equal to or larger than the target resolution, the nearest available resolution smaller than the target resolution will be chosen.

Parameters
resolution Size: The target resolution to choose from supported output sizes list.

Returns
ImageAnalysisConfig.Builder The current Builder.

setTargetRotation

public ImageAnalysisConfig.Builder setTargetRotation (int rotation)

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

This is one of four valid values: Surface.ROTATION_0, Surface.ROTATION_90, Surface.ROTATION_180, Surface.ROTATION_270. Rotation values are relative to the "natural" rotation, Surface.ROTATION_0.

Parameters
rotation int: The rotation of the intended target.

Returns
ImageAnalysisConfig.Builder The current Builder.