googlesamples / android-vision

Deprecated: The Mobile Vision API is now a part of ML Kit: Check out this repo:
https://github.com/firebase/quickstart-android/tree/master/mlkit
Apache License 2.0
2.92k stars 1.73k forks source link

Auto Focus not working / No option to set it #2

Open dhartwich1991 opened 9 years ago

dhartwich1991 commented 9 years ago

Just checked out the code for the multi-tracker application and compiled it to my device. When I tried to scan barcodes it failed, because there is no auto focus which makes it really hard to scan barcodes without any problems. The CameraSource class does not provide any options to set an auto focus option.

revanmj commented 9 years ago

Same here. Small sized codes cannot be recognized because they are all completely blurred while camera is close or really tiny when it's away and image is sharp.

DevGary commented 9 years ago

Same. Faces and some QR codes work fine but barcodes need autofocus to work as they're a lot more intricate.

pm0733464 commented 9 years ago

Sorry about that. We are working on adding an auto focus option to CameraSource and will let you know when a fix is available.

Aeefire commented 9 years ago

meanwhile, you can use this fix https://gist.github.com/Gericop/7de0b9fdd7a444e53b5a

it works for me until the library is updated.

crebstock commented 9 years ago

Unless I'm missing something, this would also be the way you would go about turning torch mode on.

gregkorossy commented 9 years ago

Yes, that's the way to do it. Actually, this method I provided only does the focus thing in order to make the Vision API actually work on barcodes, but you can change it so that it returns the Camera instance (or null on failure), then use that to modify the camera's parameters (focus, flash, etc.).

Edit: I extracted the camera getting parts so one can set any of the parameters of the used camera instance this way until Google releases the fix. https://gist.github.com/Gericop/364dd12b105fdc28a0b6

truizlop commented 9 years ago

This solution does not work for me. It doesn't enable auto focus. I made sure that it is called when the camera is displaying. Besides, sometimes I am able to read 1D codes, but the raw value doesn't match the barcode value, and it returns different values every time I try to read the same barcode.

pm0733464 commented 9 years ago

Can you post the code that you wrote to try to enable auto focus?

Note that some devices don't support camera auto focus (hardware limitation). See the comment that I just added here: https://gist.github.com/Gericop/7de0b9fdd7a444e53b5a

gregkorossy commented 9 years ago

What device are you testing on? It is possible your device doesn't support continuous auto focus. Where did you put your cameraFocus(...) call? I put it in CameraSourcePreview's startIfReady() like this:

private void startIfReady() throws IOException {
    if (mStartRequested && mSurfaceAvailable) {
        mCameraSource.start(mSurfaceView.getHolder());
        // ###### HERE IS THE FOCUS CALL ######
        MultiTrackerActivity.cameraFocus(mCameraSource, Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
        // ####################################
        if (mOverlay != null) {
            Size size = mCameraSource.getPreviewSize();
            int min = Math.min(size.getWidth(), size.getHeight());
            int max = Math.max(size.getWidth(), size.getHeight());
            if (isPortraitMode()) {
                // Swap width and height sizes when in portrait, since it will be rotated by
                // 90 degrees
                mOverlay.setCameraInfo(min, max, mCameraSource.getCameraFacing());
            } else {
                mOverlay.setCameraInfo(max, min, mCameraSource.getCameraFacing());
            }
            mOverlay.clear();
        }
        mStartRequested = false;
    }
}

You might also want to try to invoke the method with a direct action, like in a button's onClickListener.

truizlop commented 9 years ago

That's exactly the code I am using. Probably it is because my phone doesn't support auto focus. 2D barcodes are read correctly, but 1D, when they are read, provide different values for different scans.

pm0733464 commented 9 years ago

We have recently open sourced the CameraSource class:

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 has an auto-focus option.

thanhcs94 commented 8 years ago

How to call auto-focus option of CameraSource , i'm trying to call it but getting fail...now in my case ..onPictureTaken resulting in very poor quality images.. can anyone help me..??

pm0733464 commented 8 years ago

Can you post your code that creates the CameraSource and the failure messages that you are getting?

pm0733464 commented 8 years ago

Update: The CameraSource implementation provided by Google Play Services 8.4 includes an auto focus option.

ChristianKatzmann commented 8 years ago

@pm0733464 Do you have any plans to extend the official CameraSource implementation by the flash mode option that is already available in the open-source CameraSource version?

pm0733464 commented 8 years ago

We could include the flash mode if there is sufficient demand.

gregkorossy commented 8 years ago

I think the whole open source CameraSource could (should?) replace the official one as it offers more options to the devs.

ChristianKatzmann commented 8 years ago

Totally. Are there any downsides if the official CameraSource would be extended by the flash mode options?

ChristianKatzmann commented 7 years ago

@pm0733464 : Any progress on extending the official CameraSource by the flash mode options?

naveeng915213 commented 7 years ago

@pm0733464: Hi am using vision api to scan barcode, as autofocus is not working in samsung tab 3.. I donno how to figure it out whats the problem is. but when I installed the apps present in store, those are well scanning and autofocusing in my samsung tablet, I donno why google vision api is failing to do so.. please can you help me out to fix this issue.

onuryurtturk commented 6 years ago

hi, is there any solution? its a major problem for us. Only got focus by clicking to screen. Its not a good way...

onuryurtturk commented 6 years ago

@theoreticalb @claywilkinson @pm0733464 @pchx @omares @Gericop @incon @bhargavms @mbg1 @AdamSHurwitz @paolorotolo @ragdroid @Morion-Self @gonzapico