Now you can Subscribe using RSS

Submit your Email

Thursday

OpenCV for Android Camera Orientation | Show fullscreen camera preview

Vishal Shrestha
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">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
 </activity>
2. Go to your activity that displays either JavaCameraView or CameraBridgeViewBase and set the fullscreen mode on. You can do that using -
//FULLSCREEN MODE
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);



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.

Vishal Shrestha / Author & Founder

A developer by profession, a born Adventurer. I mainly do Android but like to get my hands dirty with web development and a little bit of Python. I would't rather go on a Trek than a party and you can find me having a few rounds with the heavy bag to let out the steam ;)

For Business info : My Portfolio Site.

0 comments:

Post a Comment

Coprights @ 2017 | The Code City by Vishal Shrestha Vishal Shrestha