Does mirroring the (front) camera affect MLKit with CameraX?
Asked Answered
E

0

1

You might consider this question a sequel to this other one I've recently asked. I have a custom device with a front camera that is mirrored by default and I would like it to always behave like it was flipped horizontally. Note that the end goal of my app is to perform face, barcode and facemask detection (the last one with a custom .tflite model), and I'm trying to understand if it's possible with the current state of CameraX and the quirks of the device I'm using.

  • For the preview, I can force PreviewView to use a TextureView by calling PreviewView#implementationMode = PreviewView.ImplementationMode.COMPATIBLE so I can just call PreviewView#setScaleX(-1) and it gets displayed like I want.
  • For taking pictures, I haven't tried yet but I know I can pass setReversedHorizontal(true) to the ImageCapture.OutputFileOptions used in the ImageCapture.Builder, so the image should be saved in reverse.
  • For image analysis I really don't know. If the input image is taken directly from the preview stream, then it should still be in its default state because PreviewView#setScaleX(-1) only flips the View on screen, right? So in my Analyzer's analyze() I would need to convert the ImageProxy#image to bitmap, then flip it and pass the result to InputImage.fromBitmap().

Is this everything I need? Is there a better way to do this?

Ectosarc answered 6/1, 2021 at 12:11 Comment(3)
The input of MLKit are buffer and rotation only, so it is not aware of whether the picture is mirrored. Of course you need to mirror the coordinates of detected objects but otherwise it should have no effect.Marquise
@Xi张熹 By mirroring the coordinates you mean like inverting manually all the facial landmarks values?Ectosarc
Yes that's correct. something like x' = width - xMarquise

© 2022 - 2025 — McMap. All rights reserved.