First time here? Check out the FAQ!

Ask Your Question
0

How can i change orientation without ruin camera settings?

asked Sep 8 '13

itay gravatar image

updated Sep 8 '13

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!

Preview: (hide)

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 (Dec 30 '17)edit

1 answer

Sort by » oldest newest most voted
1

answered Sep 10 '13

itay gravatar image

updated Sep 10 '13

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.

Preview: (hide)

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 (Oct 10 '13)edit

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

itay gravatar imageitay (Oct 15 '13)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 (May 13 '14)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 (Jan 25 '15)edit

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

ziarno gravatar imageziarno (Sep 16 '17)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 (Nov 5 '19)edit

Question Tools

Stats

Asked: Sep 8 '13

Seen: 17,716 times

Last updated: Sep 10 '13