I've made a simple script to decode qr. In general it works fine but there are some qr that it can't get to decode. Is there any parameters that I could adjust or something I'm missing?
version: v0.1.8
#! /usr/local/bin/python3.9
import numpy as np
from argparse import ArgumentParser
from PIL import Image
from pyzbar.pyzbar import decode, ZBarSymbol
parser = ArgumentParser()
parser.add_argument('-f', '--file', type=str)
parser.add_argument('-d', '--debug', default=False, action='store_true')
args = parser.parse_args()
thresh = 127
maxval = 255
def find_qr(img: Image, page):
imgArr = np.array(img)
imgBin = np.uint8((imgArr > thresh) * maxval)
if args.debug:
Image.fromarray(imgBin).save('img-%d.png' % page)
# uncomment to skip binarization
# imgBin = img
# imgBin.save('img-%d.png' % page)
data = decode(imgBin, symbols=[ZBarSymbol.QRCODE])
if not data is None and len(data) > 0 and data[0].type == 'QRCODE':
print(data[0].data.decode(), end='')
return True
return False
find_qr(Image.open(args.file).convert('L'), 0)
Original image:
Binarization of the image:
I've tried to decode without binarization and binarizing with higher and lower thresholds but never get's decoded.
I've tried several online decoders which can decode original image as well as binarized:
Thanks for this awesome library!
I've made a simple script to decode qr. In general it works fine but there are some qr that it can't get to decode. Is there any parameters that I could adjust or something I'm missing?
version: v0.1.8
Original image:
Binarization of the image:
I've tried to decode without binarization and binarizing with higher and lower thresholds but never get's decoded.
I've tried several online decoders which can decode original image as well as binarized: