CoordinateTransform

@RequiresApi(value = 21)
class CoordinateTransform


This class represents the transform from one OutputTransform to another.

This class can be used to map the coordinates of one OutputTransform to another, given that they are associated with the same ViewPort. OutputTransform can represent the output of a UseCase or PreviewView. For example, mapping the coordinates of detected objects from ImageAnalysis output to the drawing location in PreviewView.

// imageProxy the output of an ImageAnalysis.
OutputTransform source = ImageProxyTransformFactory().getOutputTransform(imageProxy);
OutputTransform target = previewView.getOutputTransform();

// Build the transform from ImageAnalysis to PreviewView
CoordinateTransform coordinateTransform = new CoordinateTransform(source, target);

// Detect face in ImageProxy and transform the coordinates to PreviewView.
// The value of faceBox can be used to highlight the face in PreviewView.
RectF faceBox = detectFaceInImageProxy(imageProxy);
coordinateTransform.mapRect(faceBox);

Summary

Public constructors

Creates the transform between the source and the target.

Public functions

Unit
mapPoint(point: PointF)

Apply this transform to the PointF, and write the transformed points back into the array

Unit

Apply this transform to the array of 2D points, and write the transformed points back into the array

Unit
mapRect(rect: RectF)

Apply this transform to the rectangle, and write the transformed rectangle back into it.

Unit
transform(outMatrix: Matrix)

Copies the current transform to the specified Matrix.

Public constructors

CoordinateTransform

Added in 1.1.0
CoordinateTransform(source: OutputTransform, target: OutputTransform)

Creates the transform between the source and the target.

The source and the target must be associated with the same ViewPort.

Parameters
source: OutputTransform

the source

Public functions

mapPoint

Added in 1.1.0
fun mapPoint(point: PointF): Unit

Apply this transform to the PointF, and write the transformed points back into the array

Parameters
point: PointF

The point to transform.

mapPoints

Added in 1.1.0
fun mapPoints(points: FloatArray): Unit

Apply this transform to the array of 2D points, and write the transformed points back into the array

Parameters
points: FloatArray

The array [x0, y0, x1, y1, ...] of points to transform.

See also
mapPoints

mapRect

Added in 1.1.0
fun mapRect(rect: RectF): Unit

Apply this transform to the rectangle, and write the transformed rectangle back into it. This is accomplished by transforming the 4 corners of rect, and then setting it to the bounds of those points.

Parameters
rect: RectF

The rectangle to transform.

transform

Added in 1.1.0
fun transform(outMatrix: Matrix): Unit

Copies the current transform to the specified Matrix.

Parameters
outMatrix: Matrix

a android.graphics.Matrix in which to copy the current transform.