Google se compromete a impulsar la igualdad racial para las comunidades afrodescendientes. Obtén información al respecto.

ImageAnalysis

class ImageAnalysis : UseCase
kotlin.Any
   ↳ androidx.camera.core.UseCase
   ↳ androidx.camera.core.ImageAnalysis

A use case providing CPU accessible images for an app to perform image analysis on.

ImageAnalysis acquires images from the camera via an ImageReader. Each image is provided to an ImageAnalysis.Analyzer function which can be implemented by application code, where it can access image data for application analysis via an ImageProxy.

The application is responsible for calling ImageProxy#close() to close the image. Failing to close the image will cause future images to be stalled or dropped depending on the backpressure strategy.

Summary

Nested classes
abstract

Interface for analyzing images.

Builder for a ImageAnalysis.

Constants
static Int

Block the producer from generating new images.

static Int

Only deliver the latest image to the analyzer, dropping images as they arrive.

Public methods
Unit

Removes a previously set analyzer.

Int

Returns the mode with which images are acquired from the image.

Int

Returns the number of images available to the camera pipeline, including the image being analyzed, for the STRATEGY_BLOCK_PRODUCER backpressure mode.

Int

Returns the rotation of the intended target for images.

Unit
setAnalyzer(@NonNull executor: Executor, @NonNull analyzer: ImageAnalysis.Analyzer)

Sets an analyzer to receive and analyze images.

Unit

Sets the target rotation.

String

Constants

STRATEGY_BLOCK_PRODUCER

static val STRATEGY_BLOCK_PRODUCER: Int

Block the producer from generating new images.

Once the producer has produced the number of images equal to the image queue depth, and none have been closed, the producer will stop producing images. Note that images may be queued internally and not be delivered to the analyzer until the last delivered image has been closed with ImageProxy#close(). These internally queued images will count towards the total number of images that the producer can provide at any one time.

When the producer stops producing images, it may also stop producing images for other use cases, such as Preview, so it is important for the analyzer to keep up with frame rate, on average. Failure to keep up with frame rate may lead to jank in the frame stream and a diminished user experience. If more time is needed for analysis on some frames, consider increasing the image queue depth with Builder#setImageQueueDepth(int).

Value: 1

STRATEGY_KEEP_ONLY_LATEST

static val STRATEGY_KEEP_ONLY_LATEST: Int

Only deliver the latest image to the analyzer, dropping images as they arrive.

This strategy ignores the value set by Builder#setImageQueueDepth(int). Only one image will be delivered for analysis at a time. If more images are produced while that image is being analyzed, they will be dropped and not queued for delivery. Once the image being analyzed is closed by calling ImageProxy#close(), the next latest image will be delivered.

Internally this strategy may make use of an internal Executor to receive and drop images from the producer. A performance-tuned executor will be created internally unless one is explicitly provided by Builder#setBackgroundExecutor(Executor). In order to ensure smooth operation of this backpressure strategy, any user supplied Executor must be able to quickly respond to tasks posted to it, so setting the executor manually should only be considered in advanced use cases.

Value: 0

Public methods

clearAnalyzer

fun clearAnalyzer(): Unit

Removes a previously set analyzer.

This will stop data from streaming to the ImageAnalysis.

getBackpressureStrategy

fun getBackpressureStrategy(): Int

Returns the mode with which images are acquired from the image.

The backpressure strategy is set when constructing an ImageAnalysis instance using ImageAnalysis.Builder#setBackpressureStrategy(int). If not set, it defaults to ImageAnalysis#STRATEGY_KEEP_ONLY_LATEST.

Return
Int The backpressure strategy applied to the image producer.

getImageQueueDepth

fun getImageQueueDepth(): Int

Returns the number of images available to the camera pipeline, including the image being analyzed, for the STRATEGY_BLOCK_PRODUCER backpressure mode.

The image queue depth is set when constructing an ImageAnalysis instance using ImageAnalysis.Builder#setImageQueueDepth(int). If not set, and this option is used by the backpressure strategy, the default will be a queue depth of 6 images.

Return
Int The image queue depth for the STRATEGY_BLOCK_PRODUCER backpressure mode.

getTargetRotation

fun getTargetRotation(): Int

Returns the rotation of the intended target for images.

The rotation can be set when constructing an ImageAnalysis instance using ImageAnalysis.Builder#setTargetRotation(int), or dynamically by calling ImageAnalysis#setTargetRotation(int). If not set, the target rotation defaults to the value of Display#getRotation() of the default display at the time the use case is created. The use case is fully created once it has been attached to a camera.

Return
Int The rotation of the intended target for images.

setAnalyzer

fun setAnalyzer(
    @NonNull executor: Executor,
    @NonNull analyzer: ImageAnalysis.Analyzer
): Unit

Sets an analyzer to receive and analyze images.

Setting an analyzer will signal t