I'm trying to implement JetPack Compose version of ML Kit pose detection using ML Kit Vision Quickstart Sample App
My issue is that the pose graphic overlay lines are flipped when the camera is set to LENS_FACING_FRONT.
When the camera is set toLENS_FACING_BACK
, the graphic overlay works fine.
But when the camera is set to LENS_FACING_FRONT
, the graphic overlay is horizontally flipped:
The ML Kit Vision Quickstart Sample App handles the reflection using transformationMatrix: https://github.com/googlesamples/mlkit/blob/master/android/vision-quickstart/app/src/main/java/com/google/mlkit/vision/demo/GraphicOverlay.java#L293:
transformationMatrix.reset();
transformationMatrix.setScale(scaleFactor, scaleFactor);
transformationMatrix.postTranslate(-postScaleWidthOffset, -postScaleHeightOffset);
if (isImageFlipped) {
transformationMatrix.postScale(-1f, 1f, getWidth() / 2f, getHeight() / 2f);
}
How can I do something similar in Jetpack Compose?
This is my translateX function that translates the image's coordinate system to the view's coordinate system. I think I need to modify it to handle coordinate translation when the image is flipped, but I don't know how:
fun translateX(
x: Float,
scaleFactor: Float,
postScaleWidthOffset: Float
): Float {
// Adjusts the supplied value from the image scale to the view scale
val scale = x * scaleFactor
return scale - postScaleWidthOffset
}
This is the Compose project I made if you want to take a look: ComposeMLKit