Ask Your Question
1

How to set camera resolution in OpenCV on Android?

asked 2012-08-23 09:59:05 -0500

cpares gravatar image

updated 2012-08-23 10:01:40 -0500

Hello!

I'm trying to develop an app for Android, and I would need to get a resolution as high as possible for the camera, through VideoCapture.

Right now I'm stuck in the default 960x720, which is poor for what I need, and my phone, a Samsung Galaxy S3, is able to provide, theoretically, up to 8Mpx (3,264×2,448 for pictures, and 1,920×1,080 for video, according to Wikipedia).

Is there any way to obtain a higher resolution? How?

I'm really sorry if this has been asked before; I have been looking for hours and I have found nothing.

Thank you for your time!

EDIT: I'm running OpenCV v2.4, I forgot to mention.

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
1

answered 2012-08-24 10:18:07 -0500

Rui Marques gravatar image

updated 2012-08-24 10:23:33 -0500

If you use Camera (Android) instead of VideoCapture, you can do it this way:

Camera.Parameters params = mCamera.getParameters();
List<Camera.Size> sizes = params.getSupportedPreviewSizes();

// position: variable where you choose between different supported resolutions, 
// this varies from phone to phone, even the order can be different, 
// ex. ascending or descending order.

mFrameWidth = (int) sizes.get(position).width;
mFrameHeight = (int) sizes.get(position).height;

params.setPreviewSize(mFrameWidth, mFrameHeight);
mCamera.setParameters(params); // mCamera is a Camera object

I initially wrote this answer thinking the question was about using Camera object. So for your case it should be something like this:

mFrameWidth = (int) sizes.get(position).width;
mFrameHeight = (int) sizes.get(position).height;

vc.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, mFrameWidth);
vc.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, mFrameHeight);

Be aware that getSupportedPreviewSizes() gives you video sizes and getSupportedPictureSizes() gives you camera/photograph sizes, which are different.

edit flag offensive delete link more
0

answered 2012-08-24 04:12:05 -0500

cpares gravatar image

In case anybody ever finds this useful, I found a (partial) solution: If your VideoCapture variable is called vc, this should work:

    vc.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, desiredFrameWidth);
    vc.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, desiredFrameHeight);

Mind that the combination of width and height must be one of the supported picture formats for your camera, otherwise it will just get a black image. You can get those through Camera.Parameters.getSupportedPictureSizes().

However, setting a high resolution appears to exceed the YUV conversion buffer's capacity, so I'm still struggling with that.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2012-08-23 09:59:05 -0500

Seen: 10,197 times

Last updated: Aug 24 '12