How to set Camera Resolution in Android with OpenCV

This post follows from the previous post on Creating a class that extends JavaCameraView. We can use this class to set up focus modes, flash and resolution using openCV for Android.

OpenCV for Android

It’s pretty simple to find out supported resolutions and set resolution in Android Camera using OpenCV. Just include these methods in the class that we created in the previous post and use it as you want.

Resolution List using OpenCV

public List<Camera.Size> getResolutionList() {
        return mCamera.getParameters().getSupportedPreviewSizes();
 }

 public void setResolution(Camera.Size resolution) {
        disconnectCamera();
        connectCamera((int) resolution.width, (int) resolution.height);
 }

public Camera.Size getResolution() {
        Camera.Parameters params = mCamera.getParameters();
        Camera.Size s = params.getPreviewSize();
        return s;
 }

It’s pretty simple as you can see. You can use the supported resolution that you get from getResolutionList any way you want. Try it out and do let me know if there are any problems or comment below your queries! Cheers.
Check out how to set Camera Flash in OpenCv for Android in the next post, coming soon.

Don’t miss these tips!

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

You’ve been successfully subscribed to our newsletter! See you on the other side!

Sharing is caring!

Leave a Comment

Your email address will not be published.

Exit mobile version