Python二维码扫描

模块准备

1.pyzbar

pip install pyzbar

2.PIL

注意:PIL只支持Python2,所以我们需要安装Pillow

pip install Pillow

代码示例

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')

演示

项目地址

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

猜你喜欢

转载自blog.csdn.net/Moxin1044/article/details/127237114