0

I'm trying to set picture size to change the image capture resolution of camera in Android OpenCV project which using JavaCameraView. I select the best resolution from supported resolutions and try to set it. But no matter whichever resolution I try, it doesn't work. My resolution setting code goes like this -

            List<Camera.Size> supportedSizes = params.getSupportedPictureSizes();
            if(supportedSizes!=null && supportedSizes.size()>0) {
                int maxSupportedWidth = 0, maxSupportedHeight = 0;
                for(int i=0; i<supportedSizes.size(); i++) {
                    if(supportedSizes.get(i).width >= maxSupportedWidth)
                        maxSupportedWidth = supportedSizes.get(i).width;
                }

                for(int i=0; i<supportedSizes.size(); i++) {
                    if(supportedSizes.get(i).width == maxSupportedWidth &&
                            supportedSizes.get(i).height>=maxSupportedHeight) {
                        maxSupportedHeight = supportedSizes.get(i).height;
                    }
                }
                Log.d(TAG, "Setting image capture resolution to "+maxSupportedWidth+"x"+maxSupportedHeight);
                params.setPictureSize(maxSupportedWidth, maxSupportedHeight);
            }
            mCamera.setParameters(params);

I tried calling this code in initializeCamera() function of JavaCameraView, then in onCameraViewStarted callback function and then also just before calling takePicture() function but doesn't seem to be working in any of the places. For some phones, it automatically captures large sized images but for others it doesn't. I'm presently using Redmi Phone with Android version 4.4.4 KTU84P. I tried making a different app without OpenCV using SurfaceView and android Camera class. I added the same function to set the maximum resolution and it works perfectly fine.

Please help. Any ideas on the topic would be appreciated.

Gaurav Raj
  • 699
  • 6
  • 21
  • Your code does not use JavaCV. Maybe [this answer](http://stackoverflow.com/a/12106572/192373) will help – Alex Cohn Jun 11 '16 at 18:05
  • I'm using OpenCV Android SDK not JavaCV. I'm using JavaCameraView not the native version in which camera is opened by opencv. The link you provided will help only for native case not for the Android Camera. – Gaurav Raj Jun 11 '16 at 18:38
  • On some devices, preview size and picture size should be tightly coupled. Not exactly same, naturally, but having the same aspect ratio (height/width). Mixing 9:16 and 3:4 may have weird effect on the captured photos. Could this be the case? – Alex Cohn Jun 11 '16 at 20:17
  • I tried settings most of the resolutions supported by the camera including 16:9 resolutions and 4:3 resolutions. My default preview is in 16:9 resolution. Still there is no change in the captured image size. – Gaurav Raj Jun 12 '16 at 08:22
  • setPictureSize doesn't work on any phone, whatever image size is set, its done automatically and its always in the same aspect ratio as of the preview size. Moreover I noticed that in some phones, size of captured image is not even in the list of supported picture sizes provided by the API. – Gaurav Raj Jun 12 '16 at 09:21
  • This is weird. How do you take picture? – Alex Cohn Jun 12 '16 at 10:02
  • To take picture, I just call this mCamera.takePicture(null, null, this) and receive callback in public void onPictureTaken(byte[] data, Camera camera) – Gaurav Raj Jun 12 '16 at 14:42
  • Check the parameters before calling takePicture(), most likely the pictureSize has changed. BTW, on many devices, you can set your chosen pictureSize right then! – Alex Cohn Jun 12 '16 at 16:28
  • I tried setting the picture size just before takePicture() but its of no use. Before calling takePicture, I checked the camera object, its returning me my value but capturing something else. – Gaurav Raj Jun 12 '16 at 17:30

0 Answers0