Ask Your Question
1

Mirror Image on Android Front Camera

asked Feb 8 '13

seismic gravatar image

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();
...

}

Preview: (hide)

Comments

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.

seismic gravatar imageseismic (Feb 8 '13)edit

Can you share some code?

powder366 gravatar imagepowder366 (Aug 22 '13)edit

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?

lea gravatar imagelea (Aug 17 '16)edit

2 answers

Sort by » oldest newest most voted
3

answered Feb 8 '13

rics gravatar image

Here is how your problem has been solved by a workaround. The image matrix has been rotated before its appearance.

Preview: (hide)

Comments

I couldn't find out where the BaseView is or where to implement this. Seems BaseView is not used anymore under 2.4.3.2?

seismic gravatar imageseismic (Feb 8 '13)edit

Its called CameraBridgeViewBase.java now. This solution sortof worked for me

jameo gravatar imagejameo (Mar 11 '13)edit

Some code as example?

powder366 gravatar imagepowder366 (Aug 22 '13)edit

the link is not working. Can you please share code or any other example (link) to detect faces in portrait mode full screen

vaibhav gravatar imagevaibhav (May 16 '16)edit

the link is not working, please can someone post some code ??

Lafi gravatar imageLafi (Apr 8 '17)edit
0

answered Feb 8 '13

berak gravatar image

opencv has a flip(src,dst,orientation) method

Preview: (hide)

Comments

Flipping the image and giving it back in onCameraFrame doesn't work. I think input and output image have to be of the same resolution.

seismic gravatar imageseismic (Feb 8 '13)edit

Question Tools

Stats

Asked: Feb 8 '13

Seen: 12,693 times

Last updated: Feb 08 '13