Ask Your Question
0

How can i change orientation without ruin camera settings?

asked 2013-09-08 06:20:03 -0600

itay gravatar image

updated 2013-09-08 17:58:47 -0600

Hi, I'm new with OpenCV and this is my problem:

I'm trying to change the default camera orientation, after search i found the solution.

I added this lines to the JavaCameraView.java file that including in the OpenCV 2.4.6 library:

                setDisplayOrientation(mCamera, 90);
                mCamera.setPreviewDisplay(getHolder());

while setDisplayOrientation implemented like this:

protected void setDisplayOrientation(Camera camera, int angle){
    Method downPolymorphic;
    try
    {
        downPolymorphic = camera.getClass().getMethod("setDisplayOrientation", new Class[] { int.class });
        if (downPolymorphic != null)
            downPolymorphic.invoke(camera, new Object[] { angle });
    }
    catch (Exception e1)
    {
    }
}

My problem now is that the call to "mCamera.setPreviewDisplay" method ruin all the other settings of the camera, so now i can't play with this settings (Like change the camera priview to gray, change size, distance etc...)

What can i do to fix this?

Thanks!

edit retag flag offensive close merge delete

Comments

This solution works perfectly for me. Now the camera preview orientation is normal and full screen, but frame rate(fps) is decreased from 20-30fps to 10-12fps. in my application it is most important to get maximum frames, so it would be great if me fps is intact.

Alphabatecoder gravatar imageAlphabatecoder ( 2017-12-30 00:49:16 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-09-10 07:02:56 -0600

itay gravatar image

updated 2013-09-10 07:07:05 -0600

Ok, I found the answer.

In order to solve this problem without change any settings or change JavaCameraView.java file, just add this line to "onCameraFrame" function:

 public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
     mRgba = inputFrame.rgba();
     Mat mRgbaT = mRgba.t();
     Core.flip(mRgba.t(), mRgbaT, 1);
     Imgproc.resize(mRgbaT, mRgbaT, mRgba.size());
     return mRgbaT;
 }

Little explanation: first i load the input matrix, then i made a matrix pattern with the new size, then i flip it (so the image flip by 90 degrees) and finally i return to the original matrix size.

edit flag offensive delete link more

Comments

Hi, I have just tried your method, the image is in the correct orientation now, but it doesn't display with the right resolution on the screen. So instead of modifying JavaCameraView.java, it still doesn't give the right resolution in the correct orientation. Did you do anything else to make sure that you can display a full screen of the camera view on the screen?

John Yang gravatar imageJohn Yang ( 2013-10-10 10:51:40 -0600 )edit

In what resolution do you work and what is your device? do you use full screen?

itay gravatar imageitay ( 2013-10-15 04:48:03 -0600 )edit

Hi, i am working on face detection. After applying:

setDisplayOrientation() in JavaCameraView & image flipping in onCameraFrame()

    // TODO Auto-generated method stub
    mRgba = inputFrame.rgba();
    Mat mRgbaT = mRgba.t();
    Core.flip(mRgba.t(), mRgbaT, 1);
    Imgproc.resize(mRgbaT, mRgbaT, mRgba.size());

    mGray = inputFrame.gray();
    Mat mGrayT = mGray.t();
    Core.flip(mGray.t(), mGrayT, 1);
    Imgproc.resize(mGrayT, mGrayT, mGray.size());

the green frame to detect face disappeared.

xuan gravatar imagexuan ( 2014-05-13 12:02:18 -0600 )edit

@xuan : I am having exactly the same trouble. Did you figure out how to make it full screen (in a portrait orientation).

ahmedkhanfir gravatar imageahmedkhanfir ( 2015-01-25 12:11:25 -0600 )edit

in order to not have memory leaks you must call mRgbaT.release() before returning - helped in my case.

ziarno gravatar imageziarno ( 2017-09-16 05:02:01 -0600 )edit

Was any solution ever found for the issue of the view not being full screen in portrait mode? I'm having that same issue.

jlok gravatar imagejlok ( 2019-11-05 17:53:36 -0600 )edit

Question Tools

Stats

Asked: 2013-09-08 06:20:03 -0600

Seen: 17,591 times

Last updated: Sep 10 '13