How to set camera resolution in Android with OpenCV?

DashDotDashDot picture DashDotDashDot · Aug 24, 2012 · Viewed 14k times · Source

I'm trying to develop an app for Android, and I would need to get uncompressed pictures with a resolution as high as possible from the camera. I tried takePicture's rawCallback and postviewCallback, but they are not working.

Right now I'm trying with OpenCV (version 2.4) using VideoCapture, but 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). VideoCapture.set(Highgui.CV_CAP_PROP_FRAME_WIDTH/HEIGHT, some number) makes the camera return a black image as far as I've found.

Is there any way to obtain a higher resolution, either through OpenCV or with the Android API, without compressing?

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

Thank you for your time!

EDIT: Although it is not exactly what I was asking, I found that there is a way to do something very similar: if you set an OnPreviewCallback for the Camera, using setPreviewCallback, you do get the raw picture data from the camera (at least in the S3 I'm working with). I leave it here in case somebody finds it useful in the future.

EDIT: A partial solution is explained in an answer below. To sum up,

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

works under some conditions; please see below for further detail.

Answer

ArtemStorozhuk picture ArtemStorozhuk · Aug 25, 2012

You have to get supported camera preview resoultions by calling getSupportedPreviewSizes.

After this you can set any resolution with method setPreviewSize. And don't forget to setParameters in the end. Actally many OpenCV Android examples contain this information (look at sample3).