ImageAnalysis

public final class ImageAnalysis
extends UseCase

java.lang.Object
   ↳ 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

interface ImageAnalysis.Analyzer

Interface for analyzing images. 

class ImageAnalysis.Builder

Builder for a ImageAnalysis

Constants

int OUTPUT_IMAGE_FORMAT_RGBA_8888

Images sent to the analyzer will have RGBA format.

int OUTPUT_IMAGE_FORMAT_YUV_420_888

Images sent to the analyzer will have YUV format.

int STRATEGY_BLOCK_PRODUCER

Block the producer from generating new images.

int STRATEGY_KEEP_ONLY_LATEST

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

Public methods

void clearAnalyzer()

Removes a previously set analyzer.

int getBackpressureStrategy()

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

int getImageQueueDepth()

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

int getOutputImageFormat()

Gets output image format.

ResolutionInfo getResolutionInfo()

Gets resolution related information of the ImageAnalysis.

int getTargetRotation()

Returns the rotation of the intended target for images.

void setAnalyzer(Executor executor, ImageAnalysis.Analyzer analyzer)

Sets an analyzer to receive and analyze images.

void setTargetRotation(int rotation)

Sets the target rotation.

String toString()

Inherited methods

Constants

OUTPUT_IMAGE_FORMAT_RGBA_8888

public static final int OUTPUT_IMAGE_FORMAT_RGBA_8888

Images sent to the analyzer will have RGBA format.

All ImageProxy sent to ImageAnalysis.Analyzer.analyze(ImageProxy) will have format PixelFormat.RGBA_8888

Constant Value: 2 (0x00000002)

OUTPUT_IMAGE_FORMAT_YUV_420_888

public static final int OUTPUT_IMAGE_FORMAT_YUV_420_888

Images sent to the analyzer will have YUV format.

All ImageProxy sent to ImageAnalysis.Analyzer.analyze(ImageProxy) will have format ImageFormat.YUV_420_888

Constant Value: 1 (0x00000001)

STRATEGY_BLOCK_PRODUCER

public static final int STRATEGY_BLOCK_PRODUCER

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 ImageAnalysis.Builder.setImageQueueDepth(int).

Constant Value: 1 (0x00000001)

STRATEGY_KEEP_ONLY_LATEST

public static final int STRATEGY_KEEP_ONLY_LATEST

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

This strategy ignores the value set by ImageAnalysis.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 ImageAnalysis.Builder.setBackgroundExecutor(Executor). In order to ensure smooth operation of this backpressure strategy, any user supplied