Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to take a picture with a good resolution using the font facing camera. #19

Open
saiimons opened this issue Aug 31, 2015 · 16 comments · May be fixed by #268
Open

Impossible to take a picture with a good resolution using the font facing camera. #19

saiimons opened this issue Aug 31, 2015 · 16 comments · May be fixed by #268

Comments

@saiimons
Copy link

When setting a resolution in the preview, such as 1280x960 on a Nexus 5, the output resolution is 320x240.

The camera is set up this way:

        mCameraSource = new CameraSource.Builder(context, detector)
                .setRequestedPreviewSize(1280, 960)
                .setFacing(CameraSource.CAMERA_FACING_FRONT)
                .setRequestedFps(30.0f)
                .build();

And the picture is taken this way:

                mCameraSource.takePicture(null, new CameraSource.PictureCallback() {
                    @Override
                    public void onPictureTaken(byte[] bytes) {
                        Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
                        Log.d("BITMAP", bmp.getWidth() + "x" + bmp.getHeight());
                    }
                });

You can find the modified sample code to help reproduce the issue here

@pm0733464
Copy link
Contributor

The tricky thing about choosing the camera resolution is that the aspect ratio of the preview needs to be about the same as the aspect ratio of the picture, otherwise you'll end up with a distorted preview image. My guess is that the only supported preview/picture sizes that are close enough in aspect ratio for the Nexus 5 front facing camera hardware is 320x240 (preview) and 320x240 (picture).

It's possible that the code is too conservative about how different the preview vs. picture aspect ratios can be. I'd suggest printing out the sizes from the code below and seeing if there is a preview / picture size pair of about the same aspect ratio that you think it should be using, but is not. Let me know if this is the case.

You can see what the supported preview sizes and picture sizes are for the Nexus 5 like this:

List<android.hardware.Camera.Size> supportedPreviewSizes =
        parameters.getSupportedPreviewSizes();
List<android.hardware.Camera.Size> supportedPictureSizes =
        parameters.getSupportedPictureSizes();

@saiimons
Copy link
Author

Supported picture sizes :
capture

@saiimons
Copy link
Author

Supported preview sizes :
image

@pm0733464
Copy link
Contributor

Sorry, that seems to be a bug in CameraSource. We will take a look.

@saiimons
Copy link
Author

Thanks !

@fusion44
Copy link

fusion44 commented Sep 2, 2015

I'm also running into this problem. CameraSource.takePicure results in an image with size 1280 x 720 on my Nexus 6 but my Nexus 9 returns an image with size 320 x 1xx (I don't have the exact resolution at hand but its waaay to small)

Thanks!

@Syzygy2048
Copy link

My Nexus 6 also takes images with a resolution of 240 x 320 (portrait) from both the front and the back facing camera. Same issue with the back facing camera.

@Syzygy2048
Copy link

I managed to hack together a quick fix/hack.
If you access the Camera object via reflection you can simply do getParameters(), modify them and set them again. I hope this helps you until a fixed version comes out

@claywilkinson
Copy link
Contributor

@Syzygy2048 - the CameraSource source code has been included with the barcode reader sample, so you can use it directly vs. using reflection.

@pm0733464
Copy link
Contributor

@saiimons The open source version of CameraSource (see above) includes a fix for selecting the resolution. By default, this will select the highest resolution for taking the picture (that also matches the preview aspect ratio).

Note that the current Google Play Services version of CameraSource does not yet have this fix, but that will be corrected in a future release.

@pm0733464
Copy link
Contributor

Update:
The CameraSource in Google Play Services 8.4 nows select the highest resolution for taking a picture.

@urlAkash
Copy link

@pm0733464 Can You Provide us link!!
And how to update it into existing code

@pm0733464
Copy link
Contributor

No changes to your code are required. Taking a picture with CameraSource in Google Play Services 8.4 will automatically use the highest resolution that the camera supports (which is same aspect ratio of the preview image).

@ghost
Copy link

ghost commented Oct 23, 2016

I have the same problem on Moro G3 and Sony Xperia C4.

What is the way to fix it?

@diedel
Copy link

diedel commented Jul 7, 2017

I've set setRequestedPreviewSize(640, 480) to cameraSource and I've checked the supportedPreviewSizes and supportedPictureSizes of both the front and back cameras: the 640x480 is supported. Nevertheless I always receive pictures of size 2576x1932...
The problem is that I need low resolution to pass to the Face Detector as it is very slow with that high resolutions.

@diedel
Copy link

diedel commented Jul 10, 2017

Well, I analyzed in depth the code and, as you say, it selects the picture size of high resolution available, although the preview size is 640x480.
Then, if I want a picture size of 640x480, what can I do? Scaling down the picture maybe, in CameraSource.PictureCallback?

@IvanBean IvanBean linked a pull request Oct 2, 2017 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants