public static interface ImageAnalysis.Analyzer

Interface for analyzing images.

Implement Analyzer and pass it to ImageAnalysis.setAnalyzer(Executor, Analyzer) to receive images and perform custom processing by implementing the analyze(ImageProxy) function.


Public methods

abstract void analyze(ImageProxy image)

Analyzes an image to produce a result.

Public methods


public abstract void analyze (ImageProxy image)

Analyzes an image to produce a result.

This method is called once for each image from the camera, and called at the frame rate of the camera. Each analyze call is executed sequentially.

It is the responsibility of the application to close the image once done with it. If the images are not closed then it may block further images from being produced (causing the preview to stall) or drop images as determined by the configured backpressure strategy. The exact behavior is configurable via ImageAnalysis.Builder.setBackpressureStrategy(int).

Images produced here will no longer be valid after the ImageAnalysis instance that produced it has been unbound from the camera.

The image provided has format ImageFormat.YUV_420_888.

The provided image is typically in the orientation of the sensor, meaning CameraX does not perform an internal rotation of the data. The rotationDegrees parameter allows the analysis to understand the image orientation when processing or to apply a rotation. For example, if the target rotation) is natural orientation, rotationDegrees would be the rotation which would align the buffer data ordering to natural orientation.

Timestamps are in nanoseconds and monotonic and can be compared to timestamps from images produced from UseCases bound to the same camera instance. More detail is available depending on the implementation. For example with CameraX using a implementation additional detail can be found in CameraDevice documentation.

image ImageProxy: The image to analyze