从左到右用python解码二维码

Decode qr codes with python from left to right

我有一个带有几个二维码的 png,基本上看起来像这样

解码我使用的二维码 zbarlight

from PIL import Image
import zbarlight

file_path = './tests/qr_codes.png'
with open(file_path, 'rb') as image_file:
    image = Image.open(image_file)
    image.load()

codes = zbarlight.scan_codes(['qrcode'], image)
print('QR codes: %s' % codes)

我的目标是从左到右解码二维码,因此列表应如下所示:url1、url2、url3、url4、url5、ulr6。

问题:zbarlight 扫描过程的结果(列表)在我看来像是一个随机顺序。有没有办法从左到右扫描?

我在 windows,现在无法在 linux 上进行测试,但这似乎按预期工作。

import sys, os
try:
    from pyzbar.pyzbar import decode, ZBarSymbol
except:
    cmd = ('py -m pip install "pyzbar"')
    os.system(cmd)
    from pyzbar.pyzbar import decode, ZBarSymbol

try:
    from PIL import Image
except:
    cmd = ('py -m pip install "Pillow"')
    os.system(cmd)
    from PIL import Image

decoded = decode(Image.open("C:/Temp/13AZQ.png"), symbols=[ZBarSymbol.QRCODE])
qr_dic = {}
for qr in decoded:
    x = qr[2][0] # The Left position of the QR code
    qr_dic[x] = qr[0] # The Data stored in the QR code

for qr in sorted(qr_dic.keys()):
    print(qr_dic[qr])

输出:

b'url1'
b'url2'
b'url3'
b'url4'
b'url5'