Improve QR Code Recognition with ImageMagick

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
Locked
bewidia
Posts: 2
Joined: 2015-11-03T01:29:37-07:00
Authentication code: 1151

Improve QR Code Recognition with ImageMagick

Post by bewidia »

Hello,

I'm a software engineer working on a application designed to scan QR Codes from documents (PDF) to store them in the right place. I'm using ImageMagick with the command line tool to extract the pages of the documents as .PNG files and then Zbar to discover QR Codes. It works fine as long as the original document is well printed/scanned but as soon as the symbol is "damaged", Zbar can't discover anything anymore.

I'm processing the whole page but even with a focus on the QR Code, if it's not good enough, there's nothing to recover. I was wondering if there was any "magick" tool to improve the recognition.

For example, this one is damaged
Image

But the same one with its markings improved is recognized
Image

My knowledge with image processing is limited so I don't know if it's possible at all, but I was wondering if you could contrast and/or remove the with within the black lines to automatically get something close to the improved image.

Many thanks for any advice !

Jean-François

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Improve QR Code Recognition with ImageMagick

Post by fmw42 »

The fact that you have JPG images is losing some quality. Don't save intermediate images as JPG. Nevertheless, try

Code: Select all

convert qr_code_error.jpg -morphology open square:1 -threshold 76% result.png

If on Unix, then try either my script otsuthresh or kmeansthresh to do the threshold automatically.

Code: Select all

convert qr_code_error.jpg -morphology open square:1 miff:- | otsuthresh - result.png

bewidia
Posts: 2
Joined: 2015-11-03T01:29:37-07:00
Authentication code: 1151

Re: Improve QR Code Recognition with ImageMagick

Post by bewidia »

It worked with a threshold of 85% and 90% !
Now I have to figure out what threshold works with most of my unrecognized documents.

(I'm using PNG files to process Zbar, JPG were just used to share my issue)

Many thanks !

Jean-François

Locked