NaturalHistoryMuseum / pyzbar

Read one-dimensional barcodes and QR codes from Python 2 and 3.
MIT License
718 stars 175 forks source link

Adding extra 0's to UPC-E barcode (8 digit barcodes to match length of 12 digits). #160

Open FDUS105301 opened 7 months ago

FDUS105301 commented 7 months ago

On scanning UPC-E type barcodes which consist of 8 digits, the result is being changed to match a 12 digit barcode by adding 0's in the middle of the barcode.

For example: on scanning 06541238 the barcode reader will return 065400001238.

This behavior, to my knowledge, cannot be changed. Pyzbar version: 0.1.9 Python version: 3.9.0

Code:

def init_scan(image_path): 
    #Fallback for opencv scan failure
    try:
        image = cv2.imread(image_path)
        decoded = pyzbar.decode(image)
        if decoded != []:
            return {'success':True, 'data':decoded[0].data}
        else:
            return {'success':False, 'data':''}
    except:
        return "Error"