【问题标题】:Decode qr codes with python from left to right用python从左到右解码二维码
【发布时间】:2018-07-05 15:54:36
【问题描述】:

我有一个带有几个二维码的 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 扫描过程的结果(列表)在我看来就像一个随机顺序。有没有办法从左到右扫描?

【问题讨论】:

  • 将代码拆分为单独的图像,并按所需顺序排列。
  • @Prune:我想过。问题是我有数百个文件,有时我在一页上有 3、4、5 或 6 个二维码。如何自动拆分/提取单独文件中的二维码?
  • 您应用图像处理技术来找到定义每个单独代码的特征:垂直白色带、三个角或任何适合您的。
  • 在这里发布一个完整的问题也可能会有所帮助:包括您想要的订单和您得到的订单。除非我们已经拥有二维码扫描仪,否则我们无法自行解码。

标签: python linux python-3.x qr-code zbar


【解决方案1】:

我在 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'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 2017-09-11
    • 1970-01-01
    • 2022-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多