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.
After the analyzer function returns, the ImageProxy will be closed and the
corresponding Image is released back to the ImageReader.
Summary
Nested classes | |
|---|---|
interface |
ImageAnalysis.Analyzer
Interface for analyzing images. |
enum |
ImageAnalysis.ImageReaderMode
The different ways that the image sent to the analyzer is acquired from the underlying |
Public constructors | |
|---|---|
ImageAnalysis(ImageAnalysisConfig config)
Creates a new image analysis use case from the given configuration. |
|
Public methods | |
|---|---|
ImageAnalysis.Analyzer
|
getAnalyzer()
Retrieves a previously set analyzer. |
void
|
removeAnalyzer()
Removes a previously set analyzer. |
void
|
setAnalyzer(ImageAnalysis.Analyzer analyzer)
Sets an analyzer to receive and analyze images. |
void
|
setTargetRotation(int rotation)
Sets the target rotation. |
String
|
toString()
|
Inherited methods | |
|---|---|
Public constructors
ImageAnalysis
public ImageAnalysis (ImageAnalysisConfig config)
Creates a new image analysis use case from the given configuration.
| Parameters | |
|---|---|
config |
ImageAnalysisConfig: for this use case instance
|
Public methods
getAnalyzer
public ImageAnalysis.Analyzer getAnalyzer ()
Retrieves a previously set analyzer.
| Returns | |
|---|---|
ImageAnalysis.Analyzer |
The last set analyzer or null if no analyzer is set.
|
removeAnalyzer
public void removeAnalyzer ()
Removes a previously set analyzer.
This is equivalent to calling setAnalyzer(null). This will stop data from
streaming to the ImageAnalysis.
setAnalyzer
public void setAnalyzer (ImageAnalysis.Analyzer analyzer)
Sets an analyzer to receive and analyze images.
Setting an analyzer will signal to the camera that it should begin sending data. The
stream of data can be stopped by setting the analyzer to null or by calling removeAnalyzer().
Applications can process or copy the image by implementing the ImageAnalysis.Analyzer. If
frames should be skipped (no analysis), the analyzer function should return, instead of
disconnecting the analyzer function completely.
Setting an analyzer function replaces any previous analyzer. Only one analyzer can be set at any time.
| Parameters | |
|---|---|
analyzer |
ImageAnalysis.Analyzer: of the images or null to stop data streaming to
ImageAnalysis.
|
setTargetRotation
public void setTargetRotation (int rotation)
Sets the target rotation.
This informs the use case so it can adjust the rotation value sent to
ImageAnalysis.Analyzer.analyze(ImageProxy, int).
In most cases this should be set to the current rotation returned by Display.getRotation(). In that case, the rotation parameter sent to the analyzer will be
the rotation, which if applied to the output image, will make the image match the display
orientation.
While rotation can also be set via
ImageAnalysisConfig.Builder.setTargetRotation(int), using
setTargetRotation(int) allows the target rotation to be set
dynamically. This can be useful if an app locks itself to portrait, and uses the orientation
sensor to set rotation, to process landscape images when the device is rotated by examining
the rotation received by the Analyzer function.
If no target rotation is set by the application, it is set to the value of
Display.getRotation() of the default display at the time the
use case is created.
| Parameters | |
|---|---|
rotation |
int: Target rotation of the output image, expressed as one of
Surface.ROTATION_0, Surface.ROTATION_90,
Surface.ROTATION_180, or Surface.ROTATION_270.
|
toString
public String toString ()
| Returns | |
|---|---|
String |
|
Interfaces
- CameraControl
- CameraX.ErrorListener
- Config
- Config.ExtendableBuilder
- ImageAnalysis.Analyzer
- ImageCapture.OnImageSavedListener
- ImageInfo
- ImageProxy
- ImageProxy.PlaneProxy
- ImageProxyBundle
- MutableConfig
- Observable
- Observable.Observer
- OnFocusListener
- Preview.OnPreviewOutputUpdateListener
- UseCaseEventConfig
- UseCaseEventConfig.Builder
Classes
Enums
Exceptions
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.