如何在单独的图像中分割二维码?

时间:2018-07-05 16:21:26

标签: python linux image qr-code

我有数百张带有qr码的图片(有时一页上有0、1、2或更多的qr码...但它们始终在一行中)。我要decode the qr codes from left to right。我的想法是将二维码拆分为单独的图像。

有人知道这个问题的Linux(或Python)解决方案吗?

enter image description here

我想要的顺序是:url1,url2,url3,url4,url5,url6。

1 个答案:

答案 0 :(得分:2)

我在Windows上,目前无法在linux上进行测试,但这似乎可以正常工作。

ASTMatcher

输出:

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