0

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?

9
  • Maybe it's being processed in text mode? In text mode, it can only process ASCII characters. Data Matrix - Wikipedia Is there any option in both software to explicitly specify Base256 mode, both when encoding and when decoding? Perhaps if you're dealing with ISO-8859-1 encoded data, you'll probably need to set those modes and options to convert the string to a byte array. Commented Feb 2, 2021 at 2:41
  • Could you share your image of the barcode of DataMatrix with ISO-8859-1 encoding? We will forward the case to our research team for further investigation. Thanks! -- From ML Kit Team Commented Feb 19, 2021 at 21:28
  • @JulieZhou Just added an example of an official German Medication Plan DataMatrix with ISO-8859-1 encoding. Thank you in advance for your help! Commented Feb 22, 2021 at 19:00
  • Thanks Dirk, will take a further look with the example barcode. Commented Feb 23, 2021 at 14:46
  • Thank you, Julie! Hope there's a solution - it's a rather common usecase. Ugly that we still have to deal with non-unicode encodings, but there's no choice. Commented Feb 23, 2021 at 20:46

2 Answers 2

0

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

Sign up to request clarification or add additional context in comments.

7 Comments

Sorry about the padding, but it still fails. In my app, the output of barcode?.rawvalue contains random "Unknown encoding" strings: <MP v="026" U="E96E28692A2444A38661426EBEDAF0A8" l="de-DE"><P Unknown encoding="U123456789" ... Output with ZXing: <MP v="026" U="E96E28692A2444A38661426EBEDAF0A8" l="de-DE"><P g="Bärbel" f="Müller" egk="U123456789" ...
Hi, by using mlkit vision quiclkstart app, with your BarcodeScanner setting I can get result from both a live preview when scanning this barcode and also with this image downloaded to my devices and converted to a bitmap. Could you check the mlkit quickstart app code here: github.com/googlesamples/mlkit/blob/… for reading a bitmap from url and feed it to the barcode scanner api? There might be an issue with the InputImage.
Hi Chenxi, right now, I retried with Vision QuickStart, again with the same result, again broken. See the "Unknown Encoding" string breaking the XML due to the Non-ASCII characters: 2021-03-03 20:22:21.496 18480-18480/com.google.mlkit.vision.demo I/BarcodeProcessor: <MP v="026" U="E96E28692A2444A38661426EBEDAF0A8" l="de-DE"><P Unknown encoding="U123456789" b="19400101"/> ...
Hey sorry for misreading your previous reply. I will check with internal teams to see if they can improve this result. "barcode raw value: <MP v="026" U="E96E28692A2444A38661426EBEDAF0A8" l="de-DE"><P Unknown encoding="U123456789" b="19400101"/><A lanr="123456789" n="Dr. med. Günther Brinkmann" s="Schwarzwaldstraße 1" z="79244" Unknown encoding="07636/123456" t="2021-10-10T11:12:13"/><O/><S><M p="8461367" m="1" du="1"/><M p="12453008" m="1"/><M p="5007679" m="1" d="1"/><M p="4007393"Unknown encoding"
Hi Dirk Spöri, do you mind us to use this image in our internal unit test?
|
0

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'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.