logo

... qr code: settings



Notes

You can explore many settings when writing a QR code.

qr = qrcode.QRCode(
    version=1,
    error_correction=qrcode.constants.ERROR_CORRECT_H, # L -> M -> Q -> H
    box_size=5,
    border=4,
)
qr.add_data('https//calmcode.io')
qr.make(fit=True) # Setting fit=True ensures the minimum size.

img = qr.make_image(fill_color="black", back_color="white")
img

If you're interested in running the same error-correcting experiment, you'll appreciate the following helper function.

import matplotlib.pylab as plt
from PIL import Image
import numpy as np

def convert_msg(img_path):
    img_broken = Image.open(img_path)
    np_arr = np.array(img_broken.convert('RGB'))
    data, bbox, straight_qrcode = detector.detectAndDecode(np_arr)
    print(f"found msg: {data}")
    return img_broken

convert_msg('high-quality.png')

Feedback? See an issue? Something unclear? Feel free to mention it here.



If you want to be kept up to date, consider signing up for the newsletter.