Incorrect barcode read by Mobile Vision API
Recently I've been doing some kind of Android barcode scanning app. Everything was fine until I realized that the same app made by my friend on IOS is much better at detecting barcodes. Google Mobile Vision API is often wrong, it detects barcodes like "72345...." when a real barcode is "12345..." . Is this a general problem? Are there any solutions?
Sample barcode:
This barcode is detected fine when I keep my device above, but after any small move there is big chance to get incorrect code.
Solution 1:
I found that not using the first match but applying a simple debounce strategy works pretty well. For example I only consider a valid match after a barcode appears in 3 continuous frames.
This can be easily done in a custom Detector<Barcode>
that uses a com.google.android.gms.vision.barcode.BarcodeDetector
internally.
It slows down detection a bit but makes them more reliable.
Solution 2:
For anyone who wants fast solution based on google barcode sample. To the BarcodeGraphicTracker add three fields:
String currentBarcode = null;
int confirmCounter = 0;
final static int CONFIRM_VALUE = 10;
Update BarcodeUpdateListener interface with new method:
@UiThread
void onBarcodeConfirmed(Barcode barcode);
Add this snippet to the overriden onUpdate method:
if (currentBarcode != null && currentBarcode.equals(item.displayValue)){
confirmCounter++;
if (confirmCounter >= CONFIRM_VALUE){
confirmCounter = 0;
mBarcodeUpdateListener.onBarcodeConfirmed(item);
}
}else{
currentBarcode = item.displayValue;
confirmCounter = 0;
}
}
Now you can tune it by setting fps to camera source and changing CONFIRM_VALUE.