At work we use QR Codes. It’s a pretty recent thing. For a few clients we used to scan pages of a file and then have the scanner operator stop what they were doing to give the TIFF file a meaningful filename. Now we have the clients supply cover sheets, generated with custom software, that contain QR codes. These then get processed after scanning and before the scan of the header sheet is discarded the indexing data is decoded using ZBar through an AutoHotkey script.

A few days ago we hit a problem. We’d scanned a few thousand pages but the script was unable to decode any of the indexing data from the QR codes. Not a single page. After looking into it I found that there were quality issues with the printing of the cover sheet. I could tell that the QR code was valid because the app I use on my mobile phone could read it fine, but ZBar could not. And ZBar is what matters – I wasn’t about to sit down decoding QR codes with my phone all day.

Here’s one of the troublesome codes:

QR Before

After playing with the QR code image in Photoshop for a bit I found a way of making the code readable to ZBar. I still needed a way to process the image from within a script on the processing machines, for which we do not have a Photoshop license. GraphicsMagick to the rescue! Or ImageMagick, if that’s your thing.

The AutoHotkey script was modified so that if no data was returned when attempting to read the QR code it would run the image through an extra function outputting a ‘fixed’ version of the image to a temporary file before reading that file instead and returning the data. The clean up used in GraphicsMagick is just:

gm convert "<input filepath>" -blur 200 -level 80 "<output filepath>"

The –blur and –level values can be tweaked depending on the quality of your image, but this worked perfectly for me in all the scanned images for the dodgy batch. Here’s the cleaned QR code:

QR Before

Ok, so not actually that different to the original, but enough for ZBar to actually return data this time.

QR Before

If you’re having trouble reading a QR code, or any other barcode using ZBar then give this a try. Seeing how the Windows binary for ZBar actually uses ImageMagick I’m hoping that eventually there’ll be an auto-cleanup feature to deal with troublesome files in a later version.


comments powered by Disqus