import cv2

from pyctorama import TPSColorProcessor
from qrcode import QRColoredCode
from qrcode.util import ColorSet
from qrdecode import Scanner, QRProcessor
from qrdecode.utils.image import ImageProcessor
from qrdecode.utils.biostrip import Biostrip, ColorLines
import matplotlib.pyplot as plt

cap = cv2.VideoCapture(1)
c = ColorSet()

qr1 = QRColoredCode(color_set=c)
qr1.add_data("AliciaMorales12345")

im1 = qr1.make_image()
# im1.show()

qr2 = QRColoredCode(color_set=c)
qr2.add_data("AliciaMorales78910")

im2 = qr2.make_image()
while True:
    # Capture frame-by-frame
    ret, frame = cap.read()
    cv2.imshow('vid', frame)
    if frame is not None:


        try:
            biostrip = Biostrip(frame,
                                threshold="gaussian",
                                output_size=300,
                                output_border=20)

            #cv2.imshow("Input", frame)
            #cv2.imshow("MultiQR", biostrip.image)

            assert len(biostrip.scanner.codes) == 2
            code1 = biostrip.scanner.codes[0]
            code2 = biostrip.scanner.codes[1]
            assert isinstance(code1, ImageProcessor)
            assert isinstance(code2, ImageProcessor)

            cv2.imwrite("good.png", biostrip.image)
            print('good!')
        except Exception as e:
            print(e)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
