public final class

ImageAnalysisConfig.Builder

extends java.lang.Object

implements CameraDeviceConfig.Builder<ImageAnalysisConfig.Builder>, ImageOutputConfig.Builder<ImageAnalysisConfig.Builder>, androidx.camera.core.ThreadConfig.Builder<ImageAnalysisConfig.Builder>, UseCaseConfig.Builder<ImageAnalysis, ImageAnalysisConfig, ImageAnalysisConfig.Builder>

 java.lang.Object

↳androidx.camera.core.ImageAnalysisConfig.Builder

Overview

Builder for a ImageAnalysisConfig.

Summary

Constructors
publicBuilder()

Creates a new Builder object.

Methods
public ImageAnalysisConfigbuild()

Builds an immutable ImageAnalysisConfig from the current state.

public static ImageAnalysisConfig.BuilderfromConfig(ImageAnalysisConfig configuration)

Generates a Builder from another Config object.

public MutableConfiggetMutableConfig()

public ImageAnalysisConfig.BuildersetBackgroundExecutor(java.util.concurrent.Executor executor)

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

public ImageAnalysisConfig.BuildersetCameraIdFilter(CameraIdFilter cameraIdFilter)

Sets a CameraIdFilter that filter out the unavailable camera id.

public ImageAnalysisConfig.BuildersetCaptureOptionUnpacker(CaptureConfig.OptionUnpacker optionUnpacker)

public ImageAnalysisConfig.BuildersetDefaultCaptureConfig(CaptureConfig captureConfig)

public ImageAnalysisConfig.BuildersetDefaultResolution(Size resolution)

Sets the default resolution of the intended target from this configuration.

public ImageAnalysisConfig.BuildersetDefaultSessionConfig(SessionConfig sessionConfig)

public ImageAnalysisConfig.BuildersetImageQueueDepth(int depth)

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

public ImageAnalysisConfig.BuildersetImageReaderMode(ImageReaderMode mode)

Sets the mode that the image is acquired from .

public ImageAnalysisConfig.BuildersetLensFacing(androidx.camera.core.CameraX.LensFacing lensFacing)

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

public ImageAnalysisConfig.BuildersetMaxResolution(Size resolution)

public ImageAnalysisConfig.BuildersetSessionOptionUnpacker(SessionConfig.OptionUnpacker optionUnpacker)

public ImageAnalysisConfig.BuildersetSupportedResolutions(java.util.List<> resolutions)

public ImageAnalysisConfig.BuildersetSurfaceOccupancyPriority(int priority)

public ImageAnalysisConfig.BuildersetTargetAspectRatio(AspectRatio aspectRatio)

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

public ImageAnalysisConfig.BuildersetTargetAspectRatioCustom(Rational aspectRatio)

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

public ImageAnalysisConfig.BuildersetTargetClass(java.lang.Class<ImageAnalysis> targetClass)

public ImageAnalysisConfig.BuildersetTargetName(java.lang.String targetName)

Sets the name of the target object being configured.

public ImageAnalysisConfig.BuildersetTargetResolution(Size resolution)

Sets the resolution of the intended target from this configuration.

public ImageAnalysisConfig.BuildersetTargetRotation(int rotation)

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

public ImageAnalysisConfig.BuildersetUseCaseEventListener(androidx.camera.core.UseCase.EventListener useCaseEventListener)

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder()

Creates a new Builder object.

Methods

public static ImageAnalysisConfig.Builder fromConfig(ImageAnalysisConfig configuration)

Generates a Builder from another Config object.

Parameters:

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

Returns:

The new Builder.

public ImageAnalysisConfig.Builder setImageReaderMode(ImageReaderMode mode)

Sets the mode that the image is acquired from .

The available values are and .

Parameters:

mode: The mode to set.

Returns:

The current Builder.

public ImageAnalysisConfig.Builder setImageQueueDepth(int depth)

Sets the number of images available to the camera pipeline for 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. Increasing the image queue depth may make camera operation smoother, depending on the , at the cost of increased memory usage.

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

When the is set to , 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 applys to mode. For the value is overridden by default value.

Parameters:

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

Returns:

The current Builder.

public MutableConfig getMutableConfig()

public ImageAnalysisConfig build()

Builds an immutable ImageAnalysisConfig from the current state.

Returns:

A ImageAnalysisConfig populated with the current state.

public ImageAnalysisConfig.Builder setTargetClass(java.lang.Class<ImageAnalysis> targetClass)

public ImageAnalysisConfig.Builder setTargetName(java.lang.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: A unique string identifier for the instance of the class being configured.

Returns:

the current Builder.

public ImageAnalysisConfig.Builder setLensFacing(androidx.camera.core.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: The direction of the camera's lens.

Returns:

the current Builder.

public ImageAnalysisConfig.Builder setCameraIdFilter(CameraIdFilter cameraIdFilter)

Sets a CameraIdFilter that filter out the unavailable camera id.

The camera id filter will be used to filter those cameras with lens facing specified in the config.

Parameters:

cameraIdFilter: The CameraIdFilter.

Returns:

the current Builder.

public ImageAnalysisConfig.Builder setTargetAspectRatioCustom(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 corresponds to the width, and the denominator corresponds to the height.

The target aspect ratio is used as a hint when determining the resulting output aspect ratio which may differ from the request, possibly due to device constraints. Application code should check the resulting output's resolution.

This method can be used to request an aspect ratio that is not from the standard set of aspect ratios defined in the AspectRatio.

This method will remove any value set by setTargetAspectRatio().

For ImageAnalysis, the output is the ImageProxy passed to the analyzer function.

Parameters:

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

Returns:

The current Builder.

public ImageAnalysisConfig.Builder setTargetAspectRatio(AspectRatio aspectRatio)

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

It is not allowed to set both target aspect ratio and target resolution on the same use case.

The target aspect ratio is used as a hint when determining the resulting output aspect ratio which may differ from the request, possibly due to device constraints. Application code should check the resulting output's resolution.

Parameters:

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

Returns:

The current Builder.

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: , , , . Rotation values are relative to the "natural" rotation, .

Parameters:

rotation: The rotation of the intended target.

Returns:

The current Builder.

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.

It is not allowed to set both target aspect ratio and target resolution on the same use case.

The target aspect ratio will also be set the same as the aspect ratio of the provided . Make sure to set the target resolution with the correct orientation.

Parameters:

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

Returns:

The current Builder.

public ImageAnalysisConfig.Builder setDefaultResolution(Size resolution)

Sets the default resolution of the intended target from this configuration.

Parameters:

resolution: The default resolution to choose from supported output sizes list.

Returns:

The current Builder.

public ImageAnalysisConfig.Builder setMaxResolution(Size resolution)

public ImageAnalysisConfig.Builder setSupportedResolutions(java.util.List<> resolutions)

public ImageAnalysisConfig.Builder setBackgroundExecutor(java.util.concurrent.Executor executor)

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

Parameters:

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

Returns:

the current Builder.

public ImageAnalysisConfig.Builder setDefaultSessionConfig(SessionConfig sessionConfig)

public ImageAnalysisConfig.Builder setDefaultCaptureConfig(CaptureConfig captureConfig)

public ImageAnalysisConfig.Builder setSessionOptionUnpacker(SessionConfig.OptionUnpacker optionUnpacker)

public ImageAnalysisConfig.Builder setCaptureOptionUnpacker(CaptureConfig.OptionUnpacker optionUnpacker)

public ImageAnalysisConfig.Builder setSurfaceOccupancyPriority(int priority)

public ImageAnalysisConfig.Builder setUseCaseEventListener(androidx.camera.core.UseCase.EventListener useCaseEventListener)