How to decode QR code in Python

Free Python Code - Aug 20 '23 - - Dev Community

Hi 🙂🖐

In this post, I will show you how to decode QR code in Python using a library called pyzbar.

step 1

install pyzbar pip install pyzbar

step 2

Generate qrcode


import pyqrcode

qr = pyqrcode.create('123')
qr.png('test.png', scale=6)

Enter fullscreen mode Exit fullscreen mode

Now we have a qrcode image for the test

step 3

Write decoder script


from pyzbar.pyzbar import decode
from PIL import Image

result = decode(Image.open('test.png'))
print(result)

Enter fullscreen mode Exit fullscreen mode

Result :

[Decoded(data=b'123', type='QRCODE', rect=Rect(left=24, top=24, width=126, height=126), polygon=[Point(x=24, y=24), Point(x=24, y=150), Point(x=150, y=150), Point(x=150, y=24)], quality=1, orientation='UP')]
Enter fullscreen mode Exit fullscreen mode

Now we're done 🤗

Don't forget to like and follow 🙂

For more information
https://pypi.org/project/pyzbar/

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .