Python 如何在单独的图像中拆分二维码?
我有数百张带有二维码的图片(有时一页上有0、1、2或更多二维码……但它们总是在一行中)。我想。我的想法是将二维码分割成不同的图像 有人知道这个问题的Linux(或Python)解决方案吗Python 如何在单独的图像中拆分二维码?,python,linux,image,qr-code,Python,Linux,Image,Qr Code,我有数百张带有二维码的图片(有时一页上有0、1、2或更多二维码……但它们总是在一行中)。我想。我的想法是将二维码分割成不同的图像 有人知道这个问题的Linux(或Python)解决方案吗 我想要的顺序是:url1、url2、url3、url4、url5、url6。我在windows上,目前无法在linux上进行测试,但这似乎能按预期工作 import sys, os try: from pyzbar.pyzbar import decode, ZBarSymbol except:
我想要的顺序是: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'
它们的大小都一样吗?看起来pyzbar在处理多个二维码方面没有问题。@Marco:是的,它们是。@tgikal:zbarlight也做这个工作。问题在于顺序。pyzbar也提供了图像在其输出中的位置,排序应该不会太麻烦。将左侧位置存储为字典键,然后通过排序键返回数据对我来说似乎是最简单的方法。我只是设法完成了事情(在您的帮助下)。非常感谢!如果你也发布你的解决方案,我会接受你的答案。是的,我在一台相当封闭的计算机上,它不允许我安装zbarlight,甚至不让我看看是否可以让它以同样的方式工作。