用PYTHON从左到右解码二维码 [英] Decode qr codes with python from left to right
本文介绍了用PYTHON从左到右解码二维码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有几个二维码的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'
这篇关于用PYTHON从左到右解码二维码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文