Benedikt
Benedikt

Reputation: 190

Improve zbarimg qrcode recognition

I had a working system of scanning sheets of paper and then letting zbarimg recognize qrcodes on these sheets (while I don't know in which area the qrcode appears). Suddenly qrcode recognition got much worse and eventually stopped working at all.

The physical scanner generates PDFs from the scanned sheets of paper. I use ghostscript to convert it to a picture:

gs -sDEVICE=png16m -sCompression=lzw -r600x600 -dNOPAUSE -sOutputFile='scantest.png' scantest.pdf

This is the result: scanned page converted to png via ghostscript

When you try to read the qrcode with your smartphone, it will be recognized immediately. But when I run zbarimg:

zbarimg scantest.png

Zbarimg doesn't recognize anything:

scanned 0 barcode symbols from 1 images in 6,6 seconds

I tried to apply this solution: https://stackoverflow.com/a/40609947/4654597

But without any luck, actually it destroyed the qrcode totally:

scanned page after morphological closing

I also tried to apply a light blur filter like suggested in this post: Decode QR-Code in scanned PDF

I used ImageMagick for this task: convert scantest.png -blur 1x1 scantest_after_blur.png

I also tried 1x2, 1x3, 1x4, 1x6, 1x8 but nothing helped.

How could I get zbarimg to work again?

Upvotes: 0

Views: 3615

Answers (1)

Benedikt
Benedikt

Reputation: 190

Here is what finally worked:

convert input.png +repage -threshold 50% -morphology open square:1 output.png
zbarimg output.png

Most important is probably applying morphology. I got the whole ImageMagick command from this post: QR code detection with ZBar from console fails for valid QR codes (ZBarCam from camera detects them fine)

Upvotes: 4

Related Questions