Analyzer

interface Analyzer
androidx.camera.core.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 ImageAnalysis.Analyzer#analyze(ImageProxy, int) function.

Summary

Public methods

abstract Unit
analyze(@NonNull image: ImageProxy, rotationDegrees: Int)

Analyzes an image to produce a result.

Public methods

analyze

abstract fun analyze(@NonNull image: ImageProxy, rotationDegrees: Int): Unit

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 ImageAnalysis.BackpressureStrategy. 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 android.graphics.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 androidx.camera.camera2 implementation additional detail can be found in android.hardware.camera2.CameraDevice documentation.

Parameters
image ImageProxy: The image to analyze
rotationDegrees ImageProxy: The rotation which if applied to the image would make it match the current target rotation of ImageAnalysis. rotationDegrees will be a value in {0, 90, 180, 270}.