"""
To use numpyImage:

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

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

for ii in range(40):

    try:
        qr_version = ii+1
        qr = QRCode(version=qr_version,
                    error_correction=3,
                    box_size=1,
                    border=0,
                    image_factory=numpyImage)

        # qr.clear()
        qr.add_data("New stuff!")

        qr.make()
        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()

    except Exception as e:
        print("Esto petó: {}".format(e))






