Unknown encoding error when parsing DataMatrix with ISO-8859-1 encoding

1.8k Views Asked by At

Developing an Android application to scan Data Matrix codes using Google's MLKit, I'm unable to parse codes with data encoded in ISO-8859-1 encoding and containing Non-ASCII characters.

Here's an example: DataMatrix failing with ML Kit

val options = BarcodeScannerOptions.Builder()
    .setBarcodeFormats(Barcode.FORMAT_DATA_MATRIX)
    .build()
val scanner = BarcodeScanning.getClient(options)
scanner.process(image).addOnSuccessListener { barcodes ->
  val barcode = barcodes.firstOrNull()
  Log.i(TAG, barcode?.rawValue)
  Log.i(TAG, String(barcode?.rawBytes!!, StandardCharsets.ISO_8859_1))
}

Both log statements return a string representing "Unknown encoding" (literally).

I'm using the latest version of MLKit's barcode-scanning library:

implementation 'com.google.mlkit:barcode-scanning:16.1.1

ZXing does the job, but it's having much more difficulties recognizing real life, not-so-perfect scans.

Any idea, any hint?

2

There are 2 best solutions below

0
On BEST ANSWER

With the latest version of the ML Kit Barcode Scanning library 16.1.2, the rawBytes method now returns the expected content of the QR code, also for non-unicode encodings.

implementation 'com.google.mlkit:barcode-scanning:16.1.2'
7
On

The problem with the barcode picture is that there is no padding around the barcode, which would return an empty result.

After adding some padding around the barcode content, the barcode is detected. barcode is detected. Detected result