Ask Your Question
0

Changing OPENCV camera view orientation on androi

asked 2016-05-31 05:52:32 -0600

issa.ayoub gravatar image

I have been struggling to change the orientation of the OPENCV on my android 4.4.2 OS version. It is appearing in the landscape mode. Looks exactly like:image description

I am using opencv 2.4.11 for android. My android studio version is 2.1. Many solutions exists that rely on the Camera class of android which is depricated. I have tried the: android:screenOrientation="portrait", but doesn't work I have also:

public void setResolution(Size resolution) {

disconnectCamera();
mMaxHeight = resolution.height;
mMaxWidth = resolution.width;
// mCamera.setDisplayOrientation(90);  //* Crashes if placed here
connectCamera(getWidth(), getHeight());
mCamera.setDisplayOrientation(90);  //* Doesn't crash if here, but doesn't work either

}

Some solutions suggested that I will use transpose and flip such as:

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {

Mat rgba = inputFrame.rgba();
// Rotate clockwise 90 degrees
Core.transpose(rgba, rgba);
Core.flip(rgba, rgba, 1);
... do stuff to the image ...
return rgba;

} But nothing worked out. SO I AM WONDERING Whether opencv community has a solution for this bug. If I am missing something I would like to hear from you. THANK YOU !!!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-06-02 15:15:16 -0600

issa.ayoub gravatar image

After working around this problem, it seems that the opencv camera cannot be viewed in portrait mode. The problem is solved by adding: android:screenOrientation="landscape" inside AndroidManifest.xml inside activity section. In addition, here is the onCreate(): super.onCreate(savedInstanceState); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    setContentView(R.layout.activity_main);
    mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.opencv_camera);
    mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
    mOpenCvCameraView.setCvCameraViewListener(this);

Notice where the setContentView is added. Finally, Note that my main activity extended the Activity class and the in the menifest file I added: android:theme="@android:style/Theme.NoTitleBar.Fullscreen" under the application section.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-05-31 05:52:32 -0600

Seen: 11,717 times

Last updated: Jun 02 '16