Mirror Image on Android Front Camera
I want to get OpenCV 2.4.3.2 Sample "FaceDetection" to work just like a mirror.
I changed Display Orientation in the Android Manifest to
screenOrientation="portrait"
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();
...
}
I used a workaround now. 1. I put screenOrientation to "reverseLandscape" what lets the view appear "mirrorlike". 2. In "onCameraFrame" method I can flip the image for opencv with Core. flip(src,dst,orientation) to archive face detection A side effect of this workaround is that the options bar remains on the devices right side and the software buttons(back, home etc.) on my nexus4 are on top. I have to correct that manually.
Can you share some code?
on my application i need
screenOrientation="landscape"
so i want that the options bar will be on the bottom also when the device on portrate mode. how can i change it manually?