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(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 | |
|---|---|
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. |
| Throws | |
|---|---|
IllegalStateException |
If not called on main thread. |
removeAnalyzer
public void removeAnalyzer ()
Removes a previously set analyzer.
This will stop data from streaming to the ImageAnalysis.
| Throws | |
|---|---|
IllegalStateException |
If not called on main thread. |
setAnalyzer
public void setAnalyzer (Executor executor,
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 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 | |
|---|---|
executor |
Executor: The executor in which the
ImageAnalysis.Analyzer.analyze(ImageProxy, int) will be run. |
analyzer |
ImageAnalysis.Analyzer: of the images. |
| Throws | |
|---|---|
IllegalStateException |
If not called on main thread. |
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 |
|
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.