Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

enter image description here

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
211 views
Welcome To Ask or Share your Answers For Others

1 Answer

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'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...