17

My video Camera app does record in the landscape mode, but the front facing camera previews the regular image, but the actual recording is mirrored (flipped or inverted) across the axis.

Everything works great on normal rear camera.

Can anybody suggest me a way to avoid it ? Any suggestions or source code would help a lot. Thank you.

Meghal Shah
  • 203
  • 1
  • 3
  • 6
  • Have you seen http://stackoverflow.com/questions/9754346/prevent-flipping-of-the-android-front-facing-camera/17569915#17569915 This works for API >= 14. – Steve Jul 10 '13 at 11:54

4 Answers4

11

The bad news: this mirroring is hardcoded into the camera service, and can not be disabled.

The good news: if you are on a recent API (API level >= 14), you can easily use a TextureView to mirror the preview image back to the original. Take the TextureView Example over at the Android Documentation, then use setTransform to set a mirroring transform. This will revert the preview image back to the non-mirrored original.

Note that a mirror transform is the same as a scaling transform with a -1 scale on the X axis.

If you are on an older API version, you might be able to do the same with a SurfaceView (using setScaleX, API level >= 11).

Paul-Jan
  • 16,746
  • 1
  • 63
  • 95
4

Try applying a transformation matrix to a TextureView. As per Prevent flipping of the front facing camera

This works for API level >= 14

Community
  • 1
  • 1
Steve
  • 161
  • 1
  • 4
4

You can change camera picture mirror to exact preview if you use this code

ImageCapture.Metadata metadata = new ImageCapture.Metadata();
                metadata.setReversedHorizontal(true); // This method will fix mirror issue
                options = new ImageCapture.OutputFileOptions.Builder(imageOutFile).setMetadata(metadata).build();
zia Shahid
  • 51
  • 1
  • 1
    note that you should check if lensFacing == CameraSelector.DEFAULT_FRONT_CAMERA 'cause it's inverting everything – Marina Feb 11 '22 at 08:51
0

in OpenCV JavaCameraView;

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    imageMat = inputFrame.rgba().t();
    if (//horizontal reverse)
        Core.flip(imageMat, imageMat, 1);
    else //for vertical reverse
        Core.flip(imageMat, imageMat, -1);
necip
  • 333
  • 4
  • 11