Search code examples
pythondecodeqr-code

QR-code decoding using python got too many values to unpack error


I was generating a QR code image using python.

My code:

import qrcode
data = 'Authenticated'

img = qrcode.make(data)

img.save('trademark.jpg')

After that, I wanted to fetch the information from my own generated QR code. For the above code, it would give output like name Authenticated and other information like height of the QRcode etc.

My code for fetching data of QR code:

from pyzbar.pyzbar import decode
from PIL import Image

decode_image = ("trademark.jpg")

result = decode(decode_image)

I got the error for the above code snippet

ValueError                                Traceback (most recent call last)
<ipython-input-10-dbd95bfa64b9> in <module>()
      4 decode_image = ("trademark.jpg")
      5 
----> 6 result = decode(decode_image)

1 frames
/usr/local/lib/python3.7/dist-packages/pyzbar/pyzbar.py in _pixel_data(image)
    145     else:
    146         # image should be a tuple (pixels, width, height)
--> 147         pixels, width, height = image
    148 
    149         # Check dimensions

ValueError: too many values to unpack (expected 3)

How can I debug the code?


Solution

  • I would suggest using PIL to open the image, as that is, what pyzbar is designed for:

    from pyzbar.pyzbar import decode
    from PIL import Image
    
    img = Image.open("trademark.jpg")
    result = decode(img)