OpenCV for Android Camera Orientation | Show fullscreen camera preview

OpenCV for Android is an awesome library that allows you to do a lot of cool stuff with your images.

OpenCV for Android Camera Orientation
OpenCV for Android

A common problem that many users of OpenCV4Android face is that JavaCameraView or the CameraBridgeViewBase doesn’t show full screen camera preview. It is a frustating issue for many newbie developers that are truing to use OpenCV with Android. This post describes how uou can fix camera orientation and show OpenCV JavaCameraView or CameraBridgeVIewBase preview in full screen.

How to display full screen image preview when using OpenCV for Android –

Fullscreen camera preview using openCV for Android
Default Camera orientation

I fooled around with all types of code to get a landscape full screen image preview, and it turns out doing it pretty simple, infact it doesn’t even require any OpenCV code.
Here’s how you get a fullscreen Image preview when using OpenCV for Android –

    1. Change the orientation of the activity which contains JavaCameraView or CameraBridgeViewBase to Landscape.    
     <activity android:name=".MainActivity" android:screenOrientation="landscape">
                    <action android:name="android.intent.action.MAIN"/>
                    <category android:name="android.intent.category.LAUNCHER"/>
    2. Go to your activity that displays either JavaCameraView or CameraBridgeViewBase and set the fullscreen mode on. You can do that using –
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    And Viola, that’s it! We have successfully turned the Orientation of the camera preview from OpenCV4Android. If you still have problems, fill free to contact me on my email or just comment below. Happy Coding.
    You can learn more about setting camera resolution using openCV here, or About setting flash on/off here or focus modes using openCV for Android here.

    Don’t miss these tips!

    We don’t spam! Read our privacy policy for more info.

    Sharing is caring!

    Leave a Comment

    Your email address will not be published.