I am trying to draw points on landmarks by using the result of ML-Kit Pose Detection on Android app with Jetpack Compose.
First, I draw points (red points) by using the pure coordinates that obtained from analyzer. The coordinates are representing the smaller scale of the image and points drawn on left corner of screen.
I observed that the processed image (processImage) size was scaled to 640x480. Here is analyzer code.
class PoseAnalyzer(
private val onSuccess: (result: AnalyzeResultData) -> Unit,
): ImageAnalysis.Analyzer {
private val options = PoseDetectorOptions.Builder()
.setDetectorMode(PoseDetectorOptions.STREAM_MODE)
.build()
private val poseDetector = PoseDetection.getClient(options)
@ExperimentalGetImage
override fun analyze(imageProxy: ImageProxy) {
val mediaImage = imageProxy.image
if (mediaImage != null) {
val rotationDegrees = imageProxy.imageInfo.rotationDegrees
val processImage = InputImage.fromMediaImage(mediaImage, rotationDegrees)
poseDetector.process(processImage)
.addOnSuccessListener { pose ->
val result = AnalyzeResultData(pose, processImage.toSizeData())
onSuccess(result)
}
.addOnFailureListener {
}
.addOnCompleteListener {
imageProxy.close()
}
}
}
}
Then I scaled the coordinated according to the preview size (1080x2125) by using below code.
private fun scaleAndGetOffset(
point: SizeData,
analyzedImage: SizeData,
screenSize: SizeData,
cameraSelector: CameraSelector,
): Offset {
val rateX = screenSize.x/analyzedImage.x
val rateY = screenSize.y/analyzedImage.y
return Offset(
x = if (cameraSelector == CameraSelector.DEFAULT_BACK_CAMERA) point.x * rateX else screenSize.x-point.x * rateX,
y = point.y * rateY
)
}
The point were not on correct place.
How get or convert the analyzer coordinates that will match to the preview?