Vision Barcode Scan Barcodes - tuarua/Firebase-ANE GitHub Wiki

The contents of this page are based on the original Firebase Documentation

You can use ML Kit to recognize and decode barcodes.

Configure the barcode detector

If you know which barcode formats you expect to read, you can improve the speed of the barcode detector by configuring it to only detect those formats. For example, to detect only Aztec code and QR codes, build a BarcodeDetectorOptions object as in the following example:

var options:BarcodeDetectorOptions = new BarcodeDetectorOptions();

The following formats are supported:

  • Code128
  • Code39
  • Code93
  • CodaBar
  • EAN13
  • EAN8
  • ITF
  • UPCA
  • UPCE
  • QRCode
  • PDF417
  • Aztec
  • DataMatrix

Note: For a Data Matrix code to be recognized, the code must intersect the center point of the input image. Consequently, only one Data Matrix code can be recognized in an image.

Run the barcode detector

To scan barcodes in an image, pass the image as a Bitmapdata to the BarcodeDetector's detect() method:

  1. Get an instance of CloudLandmarkDetector:
var vision:VisionANE = VisionANE.vision;
barcodeDetector = vision.barcodeDetector();
  1. Create a VisionImage object using a Bitmapdata.
var visionImage:VisionImage = new VisionImage(bmpQr.bitmapData);
  1. Then, pass the image to the detect() method:
barcodeDetector.detect(visionImage,
    function (features:Vector.<Barcode>, error:BarcodeError):void {
    if (error) {
        // ...
        return;
    }
    // ...
});

Get information from barcodes

If the barcode recognition operation succeeds, the detector returns an array of VisionBarcode objects. Each VisionBarcode object represents a barcode that was detected in the image. For each barcode, you can get its bounding coordinates in the input image, as well as the raw data encoded by the barcode. Also, if the barcode detector was able to determine the type of data encoded by the barcode, you can get an object containing parsed data.

For example:

for each (var barcode:Barcode in features) {
    var corners:Vector.<Point> = barcode.cornerPoints;
    var displayValue:String = barcode.displayValue;
    var rawValue:String = barcode.rawValue;
    var valueType:int = barcode.valueType;
    switch (valueType) {
        case 9: // wifi
            var ssid:String = barcode.wifi.ssid;
            var password:String = barcode.wifi.password;
            var encryptionType:int = barcode.wifi.type;
            break;
        case 8: // url
            var title:String = barcode.url.title;
            var url:String = barcode.url.url;
        default:
            // See API reference for all supported value types
        }
    }
}
⚠️ **GitHub.com Fallback** ⚠️