Library: Barcodes of Type UPC-A gets decoded incorrectly

Created on 7 Sep 2018  Â·  17Comments  Â·  Source: zxing-js/library

While decoding a barcode of type UPCA, the library adds a extra 0 to the decoded results. So the decoded result has 13 digits instead of 12
Please find the decoded results

{ format:7 numBits:0 rawBytes:null resultMetadata:null resultPoints: [ResultPoint, ResultPoint] text:"0885909934096" timestamp:1536309792565 ... }
screen shot 2018-09-07 at 2 14 15 pm

bug no-auto-close

Most helpful comment

All 17 comments

Stale issue message

This issue was not resolved yet.

This is still an issue?! I will investigate if i can but i have not played around with development on this library at all. i am looking for a solid barcode reader in js and this is the only working example i can find.

I believe it is. I did not work on this since I had other priorities, also I never really used UPC-A, this is entirely community sourced. Lately we begin to experience some of these strange errors as the library grows, so I had no time to go back and fix everything. Give it a try, let me know what you found. _Fun fact: I was just looking at this issue today as I had saved it to take a look later, months ago, hehe._

I will give it a look over tomorrow thanks!

The reason it is returning 13 char is due to EAN13Reader being the decoder that decodes it.
I am looking into it

/src/oned/MultiFormatUPCEANReader.ts has a comment: // todo add UPC_A, UPC_E

I have to figure out how to add one in.
Im going to attempt to copy the EAN13Reader to a UPC_A file and wire it up.

You can take a look at the Java version source code to help you.

Here we have the multi-format ONE-D, which is already used by our multi-format reader: https://github.com/zxing/zxing/blob/3c96923276dd5785d58eb970b6ba3f80d36a9505/core/src/main/java/com/google/zxing/oned/MultiFormatOneDReader.java#L37

It uses the multi-format UPC EAN reader:
image

This reader then checks if UPCA format is given in the hints map and then adds the reader:
image

So, for our code, the only thing left is check if the UPCA format hint is there and then add, this can be done in this piece of code:

https://github.com/zxing-js/library/blob/e01576b8fe812a754cdb043c15cd5ae2170e1ac3/src/core/oned/MultiFormatUPCEANReader.ts#L42-L51

With something like this:

image

The only problem is that we don't have none of those readers (UPCA, UPCE) ported yet.

Some would have to port one of them so it can work properly.

I hope it helps. 🙂

I see, you are a godsend! Thank you for the java code to use as reference! I believe I can make some progress with this, ill see what i can come up with.

OMG! its just EAN13Reader();
all i have to do is strip off the 0 at the beginning, I think i got this :P

https://github.com/zxing/zxing/blob/3c96923276dd5785d58eb970b6ba3f80d36a9505/core/src/main/java/com/google/zxing/oned/UPCAReader.java#L36

if (text.charAt(0) == '0') {
      Result upcaResult = new Result(text.substring(1), null, result.getResultPoints(), BarcodeFormat.UPC_A);
      if (result.getResultMetadata() != null) {

Edit: added file name

~Holly forking shit.~ Now who is the god sent. 😄

That's probably due to some EAN13 rule, as we can see the lib does put a zero in the start of the string in here for example: https://github.com/zxing/zxing/blob/3c96923276dd5785d58eb970b6ba3f80d36a9505/core/src/main/java/com/google/zxing/oned/EAN13Reader.java#L103

UPC can't be too hard to port, since almost everything is already in here. Anyone interested: be my guest! PRs are very welcome.

Feel free to open a draft PR If you need any help.

I will submit a draft PR tomorrow I'm sorry I spelled on this but I got
most of the code implemented I'm just not sure where I'm going wrong on it

On Sun, May 17, 2020, 11:11 PM Luiz Machado notifications@github.com
wrote:

Feel free to open a draft PR If you need any help.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/zxing-js/library/issues/88#issuecomment-629921720,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAHG3VVGU4Q5TEGP3VKBCATRSCRMLANCNFSM4FTZXNQQ
.

No worries, open it and I'll take a look ASAP. I just can't promise we will be done this week, as I have lots of important work stuff to work on, but we'll get it working soon.

https://github.com/zxing-js/library/pull/304 I have created the draft pr

its not in working order but this is my first time using typescript.

Feel free to ask if you have any difficulties. Also, this and this can help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DKhalil picture DKhalil  Â·  8Comments

boruchsiper picture boruchsiper  Â·  7Comments

josephernest picture josephernest  Â·  8Comments

sethusuryateja picture sethusuryateja  Â·  6Comments

Mazecreator picture Mazecreator  Â·  10Comments