from qrdecode.decoder import QRMatrix
from qrcode import QRCode
from qrcode.image.numpy import numpyImage
from qrcolorchecker.utils import np_img_to_gray
import matplotlib.pyplot as plt
import numpy as np

"""
To use numpyImage:

git clone https://bitbucket.org/pictoramacode/python-qrcode
cd python-qrcode
pyenv activate yourenv
pip install -e .
"""

qr = QRCode(version=7,
            error_correction=3,
            box_size=1,
            border=0,
            image_factory=numpyImage)

# qr.clear()
qr.add_data("This is new stuff for me!")

qr.make(fit=True)
qr_rgb = qr.make_image()._img

qr_gray = np_img_to_gray(qr_rgb[:, :, :3])  # Erasing alpha channel...

plt.figure()
plt.imshow(qr_gray, interpolation="none", cmap="gray")
plt.show()

decoder = QRMatrix(1 - qr_gray.astype(np.int))

decoder.decode()




