Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Mirror Image on Android Front Camera

I want to get OpenCV 2.4.3.2 Sample "FaceDetection" to work just like a mirror.

  1. I changed Display Orientation in the Android Manifest to

    screenOrientation="portrait"

  2. I say to the layout to use front camera:

<LinearLayout 
android:layout_height="match_parent" 
android:layout_width="match_parent" 
xmlns:tools="http://schemas.android.com/tools"

xmlns:opencv="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">


<org.opencv.android.JavaCameraView 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
    android:id="@+id/fd_activity_surface_view"
    opencv:camera_id="front"/> 
</LinearLayout>

Now the Screen is rotated to portrait, but the drawn image remains in landscape. how it looks now Does anyone know how to flip the image? I already tried to call the method setDisplayOrientation(90) but it doesn't work.

JavaCameraView.java:
protected boolean initializeCamera(int width, int height) 

....

AllocateCache();

mCamera.setDisplayOrientation(90);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    mSurfaceTexture = new SurfaceTexture(MAGIC_TEXTURE_ID);
    getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    mCamera.setPreviewTexture(mSurfaceTexture);
} else
   mCamera.setPreviewDisplay(null);     

mCamera.startPreview();
...

}