如何在单独的图像中拆分二维码?
How to split qr codes in separate images?
我有数百张带有二维码的图片(有时一页上有 0、1、2 或更多二维码……但它们总是在一行中)。我要。我的想法是将二维码拆分成单独的图像。
有人知道这个问题的Linux(或Python)解决方案吗?
我要的顺序是:url1、url2、url3、url4、url5、url6。
我在 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'
我有数百张带有二维码的图片(有时一页上有 0、1、2 或更多二维码……但它们总是在一行中)。我要
有人知道这个问题的Linux(或Python)解决方案吗?
我要的顺序是:url1、url2、url3、url4、url5、url6。
我在 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'