Limit decoded barcode to certain characters, e.g. hex #535
-
The barcodes I am scanning should always return a 12 character hex code, e.g AC233FD0A100. A non-trivial percentage of the time quagga detects the barcode but returns a messed up string that is not 12 char hex. It varies wildly, examples include '02', '3453456423462346563' , 'AC233F!0A100' . Repeated scanning eventually returns the correct string, but is there a way for quagga to do this internally? In other words I want to pass the desired format to quagga and have quagga keep scanning until it gets a result that matches the format. Obviously I can check the returned string in my own code and keep scanning until the desired format is returned but if quagga can already do this why reinvent the wheel?! :) EDIT: On further reading CODE128 uses three symbol sets to represent all 128 chars: 128A, 128B, 128C. which leads to another question: given that my barcodes represent only 12 digit hex codes I only need either 128A or 128B. Can quagga restrict the decoding to use only 128A for example? Would this even be meaningful or useful? (pardon my lack of knowledge) In any case if I only want 12 digit hex I would still need to do the hex check myself given that each of the three symbol sets contain non-hex characters. I think I just answered my original question :P and in fact I've already implemented the simple 12 digit hex check in my code! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Personally I scan ISBNs, use another 3rd party library to validate the codes and don't feel it makes execution much slower =) edit: I run it in Quagga.onDetected callback. I also use a very simple debounce method consisting of a "last detected values array" and a 2s timeout for cleaning it, so I avoid duplicate reads |
Beta Was this translation helpful? Give feedback.
-
There's not any currently built in method for doing this, unless there's something under the debug options that I am not familiar with. Might be something to consider for the future, though I feel like validation of a barcode could be very situationally dependent. Like, your barcodes fit that specific pattern of being a 12-digit 0-F, but the barcodes I read are "anything that UPC/EAN13 support, and the checksum digit of the barcode matches, unless i read it several times in a row with the wrong checksum, then take it anyway, because people do print barcodes without good checksums sometimes". I'd have to dig through the code for each decoder to see if they do actual character validation ie "is an exclamation mark even a valid character for this particular type of barcode?", which would be a worthy thing for each decoder to do, but I suspect they probably already do. Adding a simple validation function to call before passing anything into onDetected seems like it would be a reasonable option for the future, but the current way of doing it would be through onDetected. |
Beta Was this translation helpful? Give feedback.
Thanks for sharing your approach! I use the onDetected callback to do the simple 12 char hex check first as a pre-validation, if it fails then don't even attempt to fetch data from the db because it definitely won't exist. If it passes the check I look up the db but leave quagga running, i.e. I get subsequent detections while the fetch is in progress but simply ignore them using an
isFetching
flag until i get the response. If the fetch fails I setisFetching
to false again and the process repeats until the fetch succeeds.