android-vision icon indicating copy to clipboard operation
android-vision copied to clipboard

Will barcode scanning detection/speed be improved?

Open DevGary opened this issue 8 years ago • 10 comments

Normally I don't like to post questions in issue trackers, but I think this will be of interest to a lot of developers using this API. So here it goes:

I know this API is new, but I am wondering if there will be improvements coming or will there just be fixes and maintenance?

The reason is I played around with the barcode scanning and while it is an improvement to existing free libraries like Zxing, paid options like Scandit are still significantly faster. They seem to have a lot better low-light and blurry recognition which allows them to recognize the barcode a lot faster by not having to wait for the camera's autofocus. Unfortunately, Scandit's pricing is very steep and most developers either cannot afford it or decide to not spend the money on it. I think it would greatly improve all apps that use barcode reading if Google can offer a close or even a superior free option. And there is no reason why you guys at Google can't do that when you're already the very best at many things.

DevGary avatar Aug 16 '15 18:08 DevGary

Thanks xGary Yes - we want to improve this, and appreciate your feedback to help us do so. I believe you've seen Gericorp's suggested Autofocus workaround for now: https://gist.github.com/Gericop/7de0b9fdd7a444e53b5a Any other suggestions we should prioritize? Presumably the faster the better, but is there a specific speed you need? I'll also add a link shortly to collect feedback.

juliangsf avatar Aug 18 '15 17:08 juliangsf

Thanks!

I have used the autofocus workaround, but relying on autofocus is really the thing that is holding the detection back. I think if you try out Scandit's demo scanner in the Google Play Store, you will quickly see what makes it superior.

I think speed is definitely the first priority for most developers and their users. I think Scandit's ability to read blurry, unfocused barcodes is what makes it way faster. The Vision API is nearly instant at reading the barcode once the barcode is in focus, but waiting for the camera to focus will take a little bit of time especially on older devices. For example, I have an older phone (HTC One M7) that takes about ~2s to focus on something, once focused, the barcode gets read instantly, but it still took 2s because it relied on waiting for the camera to autofocus. When using Scandit's demo, it no longer nears to wait till the barcode is in focus so it is usually nearly instant or <300ms

DevGary avatar Aug 18 '15 18:08 DevGary

Thanks very much xGary - very helpful. We understand your issue and will take a look.

juliangsf avatar Aug 18 '15 18:08 juliangsf

@xGary, you may want to try experimenting with the different focus modes. For example, continuous picture (FOCUS_MODE_CONTINUOUS_PICTURE) is more aggressive than the video one (FOCUS_MODE_CONTINUOUS_VIDEO) so the detectors might have to wait more until the focus is set. Meanwhile, the video one is smoother, thus the detector might have some chance to detect the barcodes during the focusing process. Disclaimer: this is only an opinion, I haven't tested it.

One more thing you might find useful: try to set the focus only once (for example, trigger it manually) when you think (or the software thinks, create your algorithm for this) that the barcode is at an appropriate distance. This way, all the closer barcodes will work almost instantly since no refocusing is needed, although if you have things in the far, you might have to focus on them again. So I think the easiest way would be to let the user focus on the first barcode then just use the same focus to read more barcodes. If they want to scan farther objects, they will have to refocus, but the closer ones will work instantly.

gregkorossy avatar Aug 18 '15 20:08 gregkorossy

Blurry decoding is nessessary to improve the time before the autofocus is able to focus the code. It also helps to read very high density codes or codes that are too far away. You should also be able to read the code from every degree. Consider, that the code may have a bad orientation (roll, pitch or yaw) and is not in an optimal position to be decoded. So far, the example is able to read Codes with 0°, 90°, 180° and 270° orientation. Being able to decode in a bad illuminated room is also a bonus, so the user don't have to click on the flashlight button (if there is a flash build in).

redwolf2 avatar Aug 28 '15 20:08 redwolf2

this is my fix with Sensor.TYPE_ACCELEROMETER

    private boolean mInitialized = false;
    private float mLastX = 0;
    private float mLastY = 0;
    private float mLastZ = 0;
@Override
    public void onSensorChanged(SensorEvent event) {
        if (mCameraSource != null) {
            float x = event.values[0];
            float y = event.values[1];
            float z = event.values[2];
            Log.e(TAG, "float x = event.values[0] = " + String.valueOf(x));
            if (!mInitialized) {
                mLastX = x;
                mLastY = y;
                mLastZ = z;
                mInitialized = true;
            }
            float deltaX = Math.abs(mLastX - x);
            float deltaY = Math.abs(mLastY - y);
            float deltaZ = Math.abs(mLastZ - z);
            if (deltaX > .5 || deltaY > .5 || deltaZ > .5) {
                mCameraSource.autoFocus(myAutoFocusCallback);
            }
            mLastX = x;
            mLastY = y;
            mLastZ = z;
        }
    }

and in CameraSource.java

public void autoFocus(Camera.AutoFocusCallback autoFocusCallback) {
        if (mCamera.getParameters().getFocusMode().equals(mCamera.getParameters().FOCUS_MODE_AUTO) ||
                mCamera.getParameters().getFocusMode().equals(mCamera.getParameters().FOCUS_MODE_MACRO)) {
            mCamera.autoFocus(autoFocusCallback);
        }
    }

this approach i think is better instead of a 2 sec delay https://github.com/zxing/zxing/blob/master/android/src/com/google/zxing/client/android/camera/AutoFocusManager.java#L36

mindshifter avatar Nov 17 '15 12:11 mindshifter

Actually just comparing the speed of detection to the built in detection technology in iOS - shows a great difference. In iOS it's much much faster - and very accurate. So if I show an assistive barcode tracking graphic over the preview layout, the users feel a great difference as in iOS it is much smoother (updates around 10 times per second), and in Android it updates about 2-3 times a second. On relatively new and powerful devices. On iOS it's very easy to move the graphic to it's updated location using a UIView animation, but on Android it gets tougher - at least with the sample code - and the locations are jerky to begin with.

So an overall improvement would be great.

danielgindi avatar May 02 '17 18:05 danielgindi

Same problem for the text reader! I want to show overlays over the text but with the autofocus delays this isn't usable.

ivnsch avatar Feb 27 '18 14:02 ivnsch

I agree with @danielgindi. I have also observed in my project (where the camera get to capture a qrcode which is on the phone screen when placed in front of a mirror) capturing a qrcode is fast when camera is near to the visible qrcode. Though I don't like comparing, just to mention that the iOS device is just faster even if the camera is a not very near to the qrcode and also captures even if qrcode is small.

satyaphanindra avatar Mar 13 '18 17:03 satyaphanindra

Did anyone find a workaround for this or any technique where the speed can be improved?

LaxmikanthMadhyastha avatar Mar 25 '21 10:03 LaxmikanthMadhyastha