How to decode a QR-code image in (preferably pure) Python?

后端 未结 5 1482
时光取名叫无心
时光取名叫无心 2020-12-02 04:10

TL;DR: I need a way to decode a QR-code from an image file using (preferable pure) Python.

I\'ve got a jpg file with a

5条回答
  •  一整个雨季
    2020-12-02 04:59

    The following code works fine with me:

    brew install zbar
    pip install pyqrcode
    pip install pyzbar
    

    For QR code image creation:

    import pyqrcode
    qr = pyqrcode.create("test1")
    qr.png("test1.png", scale=6)
    

    For QR code decoding:

    from PIL import Image
    from pyzbar.pyzbar import decode
    data = decode(Image.open('test1.png'))
    print(data)
    

    that prints the result:

    [Decoded(data=b'test1', 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)])]
    

提交回复
热议问题