Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I finally figured it out!

What was happening was that when trying to extract a frame from OpenCV's onCameraFrame it was defaulting to a tiny resolution (and affected by screen size) as it was effectively taking a screenshot of what was on the screen at the time.

The solution was to implement the camera.takePicture in my own class which implemented JavaCameraView (similar to the one shown in the question here), and before taking the picture, selecting the highest possible resolution available on the device.

Code is as follows:

    fun takePic(jpgCallback: Camera.PictureCallback) {
        val params = mCamera.parameters
        params.jpegQuality = 100 //doesn't hurt to be sure

        val supportedSizes = params.supportedPictureSizes
        if (supportedSizes.isNullOrEmpty().not()) {
            var w = 0
            var h = 0
            for (size in supportedSizes) {
                if (size.width > w || size.height > h) {
                    w = size.width
                    h = size.height
                }
            }

            Log.e("----", "Using largest supported size... w: $w // h: $h")
            params.setPictureSize(w, h)
        }
        mCamera.parameters = params
        mCamera.takePicture(null, null, jpgCallback)
    }