Hacker News new | ask | show | jobs
by mfrisbie 880 days ago
QR codes are very easy to scan in-browser, but 1D barcodes are significantly more challenging. ~75% of the cannabis industry deals with Metrc, which forces companies to place 1D Code-128 barcode tags on everything they grow or manufacture. As a result, I've spent a lot of time investigating ways to scan these barcodes with a phone camera in a cross-browser webpage.

Ultimately, after much experimentation, the unavoidable conclusion is that the optical scanning solutions are junk. Connecting a crappy $20 HID bluetooth barcode scanner to a phone is so crazily better at scanning a 1D barcode than even the most massaged optical barcode scanning libraries. Industry workers that deal with these barcodes don't even bother with phone camera scanning, it's way too slow and temperamental.

4 comments

I'm not sure what they use to do it, but I'm amazed by the "Lose It!" app's barcode scanning feature. It'll scan correctly in the first fraction of a second that a barcode is visible on-screen with bad lighting, motion blur, weird/reflective colors, and crinkling.
Native apps use Android/iOS scanning libraries that are much more effective than the in-browser options. They are still nowhere near as good as hardware scanners.
At first I was angry when I had to switch to HID barcode readers because I couldn't get an app to do it well, but in the end I was very happy I did it because the ergonomics of a barcode reader are so much better than with a phone or webcam. Not just the mounting options available but also the projected red laser making things reflex-easy.

Has that been a part of your project yet? I ask because I can't easily imagine any situation where the workers would be more efficient or happier using a phone/webcam/etc to do the scannings

The initial idea involved a low-friction onboarding that didn't require any extra hardware - "Just use your phone to scan!". Stupid.

Turns out that workers would rather manually key in the last 5 numbers of a barcode to look it up than screw around with a poorly behaved camera. For the current version of the platform, it's either dedicated hardware scanning or manual ID search, the phone scanning wastes everybody's time.

I built a home-grown scanner like this one (not with ZBar though) for my asset tracking web app (www.assetbots.com) and agree that for 1D barcodes a cheap bluetooth or USB scanner is hard to beat.

We support both (camera and external), but surprisingly a lot of our customers find the camera good enough. Code 128 is our second-most scanned symbology behind QR.

A big factor in my industry was scanning damaged barcodes, which was frequent since they're attached to indoor/outdoor plants and physical boxes that get moved around. They get weathered and scraped.

If there's even slight damage to the barcode, forget the browser scanners, you can scan that thing until the next Olympics and not get a read. HID scanners don't skip a beat.

At least processing scanned 1D barcodes at resolutions of 200-300 DPI can be surprisingly hard. After deskewing the tolerances of a traditional EAN barcode are always violated due to aliasing in the image.

Probably a HID scanner has the advantage of a better spatial (horizontal) resolution?

Resolution is certainly a major factor in the scanning acuity. The browser scanning issue is somewhat paradoxical: getting a clear and high-resolution image of the barcode improves scan accuracy, but to achieve this, the camera needs to get so close to the barcode that the autofocus starts to freak out and blur the barcode. Since the browser scanner is using the browser camera API, there's no good mechanism to control the autofocus. It's enough to make you want to throw your phone in the garbage.
I’m confused why you’d need to deskew 1D barcode. 2D have the fiducials meant for image warp corrections. 1D is meant for a laser to sweep across at any odd angle up to diagonal across all the bars. Why not read the pixels in 1 horizontal row of the image and use an algorithm more like the laser does? You’re looking for alternating black/white with unknown period.
This is in fact how ZBar works, see zbar/scanner.c (source: I am the original author of the ZBar QR code support, and I was pretty envious of how easy 1D codes are, conceptually).