Read PDF417 Barcode with python

166 Views Asked by At

I am working on a Python project where I need to read PDF417 barcodes from user IDs. I am using Pyzbar library and PIL module to decode the barcodes from images. However, when I run the code, it returns an empty array even though the barcode is present in the image. I am not sure what the problem is.

To verify that the barcode is readable, I uploaded the same image to an online barcode reader This Site, which was able to display the results correctly.

Here's the code I am using:

from pyzbar import pyzbar
from PIL import Image as PIL

# Load image
image = PIL.open('b.jpg')

# Decode barcode
barcodes = pyzbar.decode(image, symbols=[pyzbar.ZBarSymbol.PDF417])
print(barcodes)

# Print barcode data
for barcode in barcodes:
    print(barcode.data.decode('utf-8'))


What could be causing the Pyzbar library to not decode the PDF417 barcode from the image? Is there something wrong with the code or the library itself? How can I fix the issue and successfully read the barcodes using Python?

0

There are 0 best solutions below