TransformationInfo
abstract class TransformationInfo
kotlin.Any | |
↳ | androidx.camera.core.SurfaceRequest.TransformationInfo |
Transformation associated the preview output.
The TransformationInfo
can be used transform the Surface
provided via SurfaceRequest#provideSurface
. The info is based on the camera sensor rotation, preview target rotation and the ViewPort
associated with the Preview
. The application of the info depends on the source of the Surface
. For detailed example, please check out the source code of PreviewView in androidx.camera.view artifact.
The info is also needed to transform coordinates across use cases. In a face detection example, one common scenario is running a face detection algorithm against a ImageAnalysis
use case, and highlight the detected face in the preview. Below is a code sample to get the transformation Matrix
based on the ImageProxy
from ImageAnalysis
and the TransformationInfo
from Preview
:
<code> // Get rotation transformation. val transformation = Matrix() transformation.setRotate(info.getRotationDegrees()) // Get rotated crop rect and cropping transformation. val rotatedRect = new RectF() rotation.mapRect(rotatedRect, RectF(imageProxy.getCropRect())) rotatedRect.sort() val cropTransformation = Matrix() cropTransformation.setRectToRect( RectF(imageProxy.getCropRect()), rotatedRect, ScaleToFit.FILL) // Concatenate the rotation and cropping transformations. transformation.postConcat(cropTransformation) </code>
Summary
Public methods | |
---|---|
abstract Rect |
Returns the crop rect rectangle. |
abstract Int |
Returns the rotation needed to transform the output from sensor to the target rotation. |
Public methods
getCropRect
@NonNull abstract fun getCropRect(): Rect
Returns the crop rect rectangle.
The returned value dictates how the Surface
provided in SurfaceRequest#provideSurface
should be displayed. The crop rectangle specifies the region of valid pixels in the buffer, using coordinates from (0, 0) to the (width, height) of SurfaceRequest#getResolution
. The caller should arrange the UI so that only the valid region is visible to app users.
If Preview
is configured with a ViewPort
, this value is calculated based on the configuration of ViewPort
; if not, it returns the full rect of the buffer. For code sample on how to apply the crop rect, please see ViewPort#FIT
.
See Also
getRotationDegrees
abstract fun getRotationDegrees(): Int
Returns the rotation needed to transform the output from sensor to the target rotation.
This is a clockwise rotation in degrees that needs to be applied to the sensor buffer. The rotation will be determined by CameraCharacteristics
, Preview#setTargetRotation(int)
and Preview.Builder#setTargetRotation(int)
. This value is useful for transforming coordinates across use cases.
This value is most useful for transforming coordinates across use cases, e.g. in preview, highlighting a pattern detected in image analysis. For correcting the preview itself, usually the source of the Surface
handles the rotation without needing this value. For SurfaceView
, it automatically corrects the preview to match the display rotation. For TextureView
, the only additional rotation needed is the display rotation. For detailed example, please check out the source code of PreviewView in androidx.camera .view artifact.
Return | |
---|---|
Int |
The rotation in degrees which will be a value in {0, 90, 180, 270}. |