Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New vision API - Picture size

I've been working on a project and got to make face detection working, with focus, thanks to SO.

I am now taking pictures, but using the front camera on my Nexus 5 and a preview size of 1280x960, the play services seem to set the picture size to 320x240.

I checked, 1280x960 is supported on both preview and picture.

I tried changing the parameters using reflection (same as for the focus), but nothing changed. Seems to be necessary to change that before starting the preview...

I've been trying to read and debug the obfuscated code, but I can't get why the library decides to go for this low resolution :-(

The code used is close to what's included in the sample, just added the possibility to take a picture using CameraSource.takePicture(...)

You can find the code in the samples repo

Code to reproduce the issue => here

I changed the camera init with :

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

Added a button and connected a clik listener :

findViewById(R.id.snap).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            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());
                }
            });
        }
    });

Log output :

BITMAP﹕ 320x240

Thanks for the help !

like image 711
Simon Guerout Avatar asked Nov 09 '22 06:11

Simon Guerout


1 Answers

We have recently open sourced the CameraSource class. See here:

https://github.com/googlesamples/android-vision/blob/master/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/ui/camera/CameraSource.java

This version includes a fix for the picture size issue. It will automatically select the highest resolution that the camera supports which matches the aspect ratio of the preview.

like image 175
pm0733464 Avatar answered Nov 14 '22 23:11

pm0733464