How to split qr codes in separate images?

妖精的绣舞 提交于 2019-12-13 09:37:04

问题


I have hundreds of pictures with qr codes (sometimes there are 0, 1, 2 or more qr codes on one page...but they are always in one line). I want to decode the qr codes from left to right. My idea is to split the qr codes in separate images.

Does somebody know a Linux (or Python) solution for this problem?

The order I want is: url1, url2, url3, url4, url5, url6.


回答1:


I'm on windows, no way of testing on linux right now, but this appears to work as expected.

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

Output:

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


来源:https://stackoverflow.com/questions/51196028/how-to-split-qr-codes-in-separate-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!