Python QR code scanning

module preparation

1. pyzbar

pip install pyzbar

2.PIL

Note: PIL only supports Python2, so we need to install Pillow

pip install Pillow

code example

from PIL import Image
import pyzbar.pyzbar as pyzbar

def QRcode_message(image):
    img = Image.open(image) # 读取图片
    # 因为一张图片可能是一张二维码,也可能里面有许多二维码
    barcodes = pyzbar.decode(img) # 解析图片信息
    for barcode in barcodes:
    # 如果图片有多个二维吗信息,会自动循环解析
        barcodeData = barcode.data.decode("utf-8")
        print(barcodeData)

if __name__ == '__main__':
    QRcode_message('test.png')

demo

project address

https://github.com/Moxin1044/QRcode_Scan
https://gitee.com/Moxin1044/QRcode_Scan

Guess you like

Origin blog.csdn.net/Moxin1044/article/details/127237114