cropRotateScaleImage

actual fun cropRotateScaleImage(frameData: CameraFrame, cx: Double, cy: Double, angleDegrees: Double, outputWidthPx: Int, outputHeightPx: Int, targetWidthPx: Int): ImageBitmap
actual fun ImageBitmap.cropRotateScaleImage(cx: Double, cy: Double, angleDegrees: Double, outputWidthPx: Int, outputHeightPx: Int, targetWidthPx: Int): ImageBitmap
expect fun cropRotateScaleImage(frameData: CameraFrame, cx: Double, cy: Double, angleDegrees: Double, outputWidthPx: Int, outputHeightPx: Int, targetWidthPx: Int): ImageBitmap

Extract an arbitrary geometry rectangular bitmap from the original bitmap.

The method can be used to crop and level the face image from the captured bitmap using MLKit face detection data as needed for further processing.

Usage Example

    // Extract the square shaped face bitmap around the center point between eyes and level it by eyes line.
val faceCenterX = (leftEye.position.x + rightEye.position.x) / 2
val faceCenterY = (leftEye.position.y + rightEye.position.y) / 2
val eyeOffsetX = leftEye.position.x - rightEye.position.x
val eyeOffsetY = leftEye.position.y - rightEye.position.y
val eyeDistance = sqrt(eyeOffsetX * eyeOffsetX + eyeOffsetY * eyeOffsetY)
val faceWidth = eyeDistance * 3 // Heuristic multiplier to fit the face normalized to the eyes pupilar distance.
val eyesAngleRad = atan2(eyeOffsetY, eyeOffsetX)
val eyesAngleDeg = eyesAngleRad * 180.0 / PI // Convert radians to degrees

// Call platform dependent bitmap transformation.
val croppedFaceImageBitmap = cropRotateScaleImage(
frameData = frameData, // Platform-specific image data.
cx = faceCenterX.toDouble(), // Point between eyes
cy = faceCenterY.toDouble(), // Point between eyes
angleDegrees = eyesAngleDeg, // Eyes line rotation.
outputWidth = faceWidth.toInt(), // Expected face width for cropping *before* final scaling.
outputHeight = faceWidth.toInt(),// Expected face height for cropping *before* final scaling.
targetWidth = 256 // Final square image size (for database saving and face matching tasks).
)

Return

An ImageBitmap representing the rotated, cropped, and scaled image.

Parameters

frameData

The camera frame data containing the original platform image bitmap reference and data.

cx

The x-coordinate of the transformations center point in the original image (new image center).

cy

The y-coordinate of the transformations center point in the original image (new image center).

angleDegrees

The angle of rotation in degrees around the center point.

outputWidth

The desired width of the output image.

outputHeight

The desired height of the output image.

targetWidth

The desired width of the final image after scaling.


expect fun ImageBitmap.cropRotateScaleImage(cx: Double, cy: Double, angleDegrees: Double, outputWidthPx: Int, outputHeightPx: Int, targetWidthPx: Int): ImageBitmap

Extract an arbitrary geometry rectangular bitmap from the original bitmap.

The method can be used to crop and level the face image from the captured bitmap using MLKit face detection data as needed for further processing.

Usage Example

    // Extract the square shaped face bitmap around the center point between eyes and level it by eyes line.
val faceCenterX = (leftEye.position.x + rightEye.position.x) / 2
val faceCenterY = (leftEye.position.y + rightEye.position.y) / 2
val eyeOffsetX = leftEye.position.x - rightEye.position.x
val eyeOffsetY = leftEye.position.y - rightEye.position.y
val eyeDistance = sqrt(eyeOffsetX * eyeOffsetX + eyeOffsetY * eyeOffsetY)
val faceWidth = eyeDistance * 3 // Heuristic multiplier to fit the face normalized to the eyes pupilar distance.
val eyesAngleRad = atan2(eyeOffsetY, eyeOffsetX)
val eyesAngleDeg = eyesAngleRad * 180.0 / PI // Convert radians to degrees

// Call platform dependent bitmap transformation.
val croppedFaceImageBitmap = cropRotateScaleImage(
frameData = frameData, // Platform-specific image data.
cx = faceCenterX.toDouble(), // Point between eyes
cy = faceCenterY.toDouble(), // Point between eyes
angleDegrees = eyesAngleDeg, // Eyes line rotation.
outputWidth = faceWidth.toInt(), // Expected face width for cropping *before* final scaling.
outputHeight = faceWidth.toInt(),// Expected face height for cropping *before* final scaling.
targetWidth = 256 // Final square image size (for database saving and face matching tasks).
)

Return

An ImageBitmap representing the rotated, cropped, and scaled image.

Parameters

cx

The x-coordinate of the transformations center point in the original image (new image center).

cy

The y-coordinate of the transformations center point in the original image (new image center).

angleDegrees

The angle of rotation in degrees around the center point.

outputWidth

The desired width of the output image.

outputHeight

The desired height of the output image.

targetWidth

The desired width of the final image after scaling.

actual fun cropRotateScaleImage(frameData: <Error class: unknown class>, cx: Double, cy: Double, angleDegrees: Double, outputWidthPx: Int, outputHeightPx: Int, targetWidthPx: Int): <Error class: unknown class>
actual fun <Error class: unknown class>.cropRotateScaleImage(cx: Double, cy: Double, angleDegrees: Double, outputWidthPx: Int, outputHeightPx: Int, targetWidthPx: Int): <Error class: unknown class>