Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can get a list of the available resolutions or setup manually.

If you want to get the list of the available sizes and get the optimal camera size.

   if (mOpenCvCameraView != null) {
        List<Size> sizes = mOpenCvCameraView.getSupportedPreviewSizes();
        int mFrameWidth = width;
        int mFrameHeight = height;

        // selecting optimal camera size
        {

            double minDiff = Double.MAX_VALUE;
            for (Size size : sizes) {
                if (Math.abs(size.height - height) < minDiff) {
                    mFrameWidth = (int) size.width;
                    mFrameHeight = (int) size.height;
                    minDiff = Math.abs(size.height - height);
                }
            }
        }

        mOpenCvCameraView.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, mFrameWidth);
        mOpenCvCameraView.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, mFrameHeight);
    }

If the optimal camera size is not fullscreen, it is easy to get the great size that the camera support from the list.

Other option is to set manually the size:

        mOpenCvCameraView.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, 1000);
        mOpenCvCameraView.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, 800);

The source of the code is from Face Detection OpenCV version 2.4.2.