ericblade / barcode-validator

Javascript nodejs barcode validation for ISBN10, ISBN13, UPC, GTIN
MIT License
3 stars 1 forks source link

How are you validating ? #3

Closed sudhamjayanthi closed 3 years ago

sudhamjayanthi commented 3 years ago

Hi @ericblade , Could you tell me what's logic behind this library ? How would you validate a barcode ?

ericblade commented 3 years ago

This just exports a single function that takes two parameters, a string representing a numeric barcode (like what you'd get from a barcode scanner), and an optional string containing what the type of barcode you're expecting it to be is.

The TypeScript definition file is pretty easy to read, even if you're not familiar with TypeScript https://github.com/ericblade/barcode-validator/blob/master/index.d.ts

It should work with anything similar to GTIN, ISBN, EAN, UPC types, I have not researched other types. The code itself, I think is pretty well documented. I personally use this in both browser and node code to determine if a barcode looks valid before sending it off to other services.

sudhamjayanthi commented 3 years ago

Ok! But I'm not asking about the code/technical part rather I would like to know the logic behind validating a barcode. What are checksums & how would you validate a barcode ? Is there some logic between the digits for every specific type of barcodes ?

P.S: I haven't worked with barcodes before.

ericblade commented 3 years ago

aha, you might want to read up on check digits for barcodes https://en.wikipedia.org/wiki/Check_digit

Basically, the last digit of most numeric barcodes is a digit that is calculated by various addition/multiplication operations.

Although, as wiki points out, the method was designed to catch human entry errors, it also can be used to catch laser and visual based scanner errors as well, to a degree.

sudhamjayanthi commented 3 years ago

Oh, Got it! Thanks. Also would using this library be helpful for increasing accuracy of quagga js while using all the barcodes set ?

ericblade commented 3 years ago

I do use it for that, although i do find that if you just rely on "valid barcode" you'll end up with a lot of false positives with the UPC reader, still. I want to try combining both validating the barcode and using a threshold of error confidence to try to get it really close.. one thing that i have noticed, is that there are some upc barcodes on products out there that actually do not validate, so even if you could guarantee never having an actual read error, relying solely on the checksum is not 100%.

sudhamjayanthi commented 3 years ago

I do use it for that, although i do find that if you just rely on "valid barcode" you'll end up with a lot of false positives with the UPC reader, still. I want to try combining both validating the barcode and using a threshold of error confidence to try to get it really close.. one thing that i have noticed, is that there are some upc barcodes on products out there that actually do not validate, so even if you could guarantee never having an actual read error, relying solely on the checksum is not 100%.

Hey sorry @ericblade, I was a bit busy & unable to reply to you!

Can you tell how to use the error confidence to improve accuracy ? I actually have also gone through this thread about limiting false positives. But I found it tough to understand to understand this thing, I also searched in the documentation and got not much help! So could please drop a link here if there is detailed explanation in the documentation or somewhere else and maybe about the result object(what information can we get from it), what is error confidence, how can prevent false positives with it, are there any other methods to prevent false positives ?

PS: Thanks a lot for being patient and answering all questions ; ) Your explanations are really helping me to understand new concepts

ericblade commented 3 years ago

I was pretty successful using a method like https://github.com/serratus/quaggaJS/issues/237#issuecomment-389667599

When I re-wrote my app, I swapped that for doing a 100% validator approach, thinking that would be better... and it's not. With the error-confidence approach, i'd find that sometimes it would take too long to get a high confidence score, but with a pure valid-checksum approach, i get a lot more false scans. So, I think there's some use to both, and a combined method might do better.

I don't really know too much about the error values, sorry. This is more a question for https://www.github.com/ericblade/quagga2 though.

sudhamjayanthi commented 3 years ago

Ok! Yeah, this is a actually a question of quagga js, but I asked it here just as continuation to your message. Pl let me know if you find out & research more about the error values when you deep dive into quagga js library.

but with a pure valid-checksum approach, i get a lot more false scans

But it does improve than having no validation right ? (like this library doesn't show the right ones too wrong right?)

ericblade commented 3 years ago

sort of, yeah. between falses and products with UPCs that don't even pass validation anyway, i think i'm going to try to take a "if median of errors is below X or if checksum matches and median of errors is below Y" approach and see how that works.. just haven't got around to it in my app because i've got a million other things