## qr_read -- for reading qr code values
from pyzbar.pyzbar import decode as decodeQR
import numpy

## reads a qr code in the image, returns a string of the data
def readQR(img):
    
    try:
        ## decode the data using pyzbar decode
        qr_data = decodeQR(img)[0][0]

        
        ## truncate the non-data and decode
        if (len(qr_data) > 3):
            qr_data = qr_data[:-2].decode()
            
        ## print the data if found, return without beginning and end
        if qr_data is not None and len(qr_data) != 0:
            print('QR code read as: \'%s\'\n' % qr_data)
            return qr_data

    except:
        print('No QR code detected.\n')
        return None
