question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Code128 ResultPoints return incorrect values

See original GitHub issue

Currently the Code128Reader reader is providing a Result information with incorrect coordinates at where the code starts and ends.

Taking the following barcode as an example: foobar

I’m getting the following results:

{
    "text": "foobar\n",
    "rawBytes": "aEZPT0JBUmVKQWo=",
    "numBits": 88,
    "resultPoints": [
    {
        "x": 59,
        "y": 122
    },
    {
        "x": 499,
        "y": 122
    }],
    "resultMetadata": {
        "SYMBOLOGY_IDENTIFIER": "]C0"
    },
    "timestamp": 1656682389903,
    "barcodeFormat": "CODE_128"
}

Now the result point 1 is [59,122], which is in de middle of the Code128 start pattern, not the start of the actual data nor the start of the barcode.

Looking at decodeRow method Code128Reader, the startPatternInfo is found first and the code is decoded. This is all correct, however at the end where the result is constructed the left and right (which are the points returned in the result) are calculated based on the startPatternInfo.

In this case left is calculated as (startPatternInfo[1] + startPatternInfo[0]) / 2.0f; here the startPatternInfo[0] has the actual position (albeit 1 pixel off in the example) of the barcode left coordinate. Right is calculated as lastStart + lastPatternSize / 2.0f which is also incorrect, since it results in the middle of the CODE_STOP of the Code128.

The fix for the left is straightforward, either use startPatternInfo[0] or “calculate it” based on startPatternInfo[1] and startPatternInfo[2] (startPatternInfo[2] - startPatternInfo[1]) which results in the same value as startPatternInfo[0];

From debugging info the startPatternInfo has the following values:

startPatternInfo[0] = 37
startPatternInfo[1] = 84
startPatternInfo[2] = 101

The fix for right requires more investigation.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
srowencommented, Jul 2, 2022

I can look at returning some other metadata that’s like ‘all points the implementation happened to find, in some impl specific order’ maybe. And leave the current return value as is as a sort of ‘key human readable locations’ Adding a bit of extra existing info to the return seems OK

1reaction
axxelcommented, Jul 1, 2022

Just name one alternative that might work a bit better for your application: https://github.com/nu-book/zxing-cpp

During reimplementation of all the 1D codes, I opted for returning ‘everything except the quite zone’ as the position of any barcode, that mostly means ‘from the first black pixel to the last black pixel’. Generally, you still have the limitation that you don’t get the full bounding box. But if you used the ReadBarcodes (multi-barcode version) function and your symbols are properly detectable and horizontally aligned you do in fact get pretty much exactly that: out .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Something wrong with barcode (Code 128) font not scanning
Code 128 can be represented with a font totally fine. ... Each character of the barcode gets a specific value assigned to it...
Read more >
Issue 156 in zxing: Barcode CODE128 not decoded if image is ...
barcode found on this image but something goes wrong in the decoding process } return result != null ? result.getText() : null;. }...
Read more >
Code 128/GS1-128 Barcode FAQ & Tutorial
The Code 128 Barcode FAQ & Tutorial provides barcode generation, printing, scanning and encoding examples for Code 128 and GS1-128 and USS Code-128....
Read more >
Wrong EAN13 code detected - am I doing something wrong?
P.S. In case it helps, the barcode was generated inside a Jasper Report, with the Barbeque library, and the document was then scanned...
Read more >
Code 128 Misreading? - BarTender Support Portal
It sounds like your scanner is doing neither and so the code is good, all be it incorrect. I would suspect that your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found