I used Zbar (and ZXing) to read the QR code in many images like the below one, but both failed to detect it. I think I need some transformation, because when I use ZBarImg from console, it fails. On the other side, when I use ZBarCam and I put the document in front of the webcam on my laptop, it detects and decodes QR code instantly.
There are images that QR is detected correctly and images really similar to the successful ones that fail.
I tried to use ImageMagick to resize the image, remove borders, greyscale, blur it, deskew, multiple scripts from @fmw42 "Fred's ImageMagick Scripts" (unperspective...). Nothing helped. I judge it has to be some simple transformation, because ZBarCam does it almost instantly.
Do you have any idea?
I am not sure what you have tried in Imagemagick, but my unperspective will not help this image. It will not correct for wrinkles.
But here is what I would do. First threshold, then apply morphology. The use connected components to get get the bounding box of QR code block. The crop the QR code out of the original image and use morphology to make the black regions more distinct.
Input:
cropvals=`magick receipt.jpg \
-auto-threshold otsu \
-morphology open square:7 \
-bordercolor black -border 1 -fill white -draw "color 0,0 floodfill" -alpha off \
-shave 1x1 \
-type bilevel \
-define connected-components:verbose=true \
-define connected-components:exclude-header=true \
-define connected-components:mean-color=true \
-connected-components 8 ccl.png | grep "gray(0)" | head -n 1 | awk '{print $2}'`
echo $cropvals
261x243+629+1829
magick receipt.jpg \
-crop $cropvals +repage \
-auto-threshold otsu \
-morphology open square:1 qcode.png