pip install pyzbar

#pip install Pillow
from pyzbar.pyzbar import decode
from PIL import Image
def decode_qr_code(image_path):
    # 打开图片
    image = Image.open(image_path)
    # 使用pyzbar的decode函数解码图片中的二维码
    decoded_objects = decode(image)
    # 输出解码结果
    for obj in decoded_objects:
        print('Type:', obj.type)
        print('Data:', obj.data.decode('utf-8'))  # 解码数据为utf-8格式
        print('Location:', obj.rect)  # 输出二维码在图片中的位置
# 调用函数,传入图片路径
decode_qr_code('I:/winpython/erweima.jpg')

erweima.jpg
识别结果如下:
77.png

标签: none