Ask Your Question
1

Mirror Image on Android Front Camera

asked 2013-02-08 09:11:04 -0600

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

}

edit retag flag offensive close merge delete

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 ( 2013-02-08 11:55:04 -0600 )edit

Can you share some code?

powder366 gravatar imagepowder366 ( 2013-08-22 15:10:37 -0600 )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 ( 2016-08-17 03:53:19 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
3

answered 2013-02-08 10:11:11 -0600

rics gravatar image

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

edit flag offensive delete link more

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 ( 2013-02-08 11:35:51 -0600 )edit

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

jameo gravatar imagejameo ( 2013-03-11 08:56:42 -0600 )edit

Some code as example?

powder366 gravatar imagepowder366 ( 2013-08-22 15:09:13 -0600 )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 ( 2016-05-16 02:05:44 -0600 )edit

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

Lafi gravatar imageLafi ( 2017-04-08 08:36:45 -0600 )edit
0

answered 2013-02-08 10:06:12 -0600

berak gravatar image

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

edit flag offensive delete link more

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 ( 2013-02-08 12:26:42 -0600 )edit

Question Tools

Stats

Asked: 2013-02-08 09:11:04 -0600

Seen: 12,632 times

Last updated: Feb 08 '13