本文介绍了如何在单独的图像中拆分qr代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有数百张带有qr代码的图片(有时在一页上有0,1,2或更多qr代码......但它们总是在一行中)。我想
我想要的订单是:url1,url2,url3,url4,url5,url6 。
解决方案
我正在使用Windows,现在无法在linux上进行测试,但这似乎按预期工作。
import sys,os
try:
来自pyzbar.pyzbar import decode,ZBarSymbol
除外:
cmd =('py -m pip installpyzbar')
os.system(cmd)
from pyzbar.pyzbar import decode,ZBarSymbol
try :
来自PIL导入图片
除了:
cmd =('py -m pip installPillow')
os.system(cmd)
来自PIL导入Image
decoding = decode(Image.open(C:/ Temp / 13AZQ .png),symbols = [ZBarSymbol.QRCODE])
qr_dic = {}
for qr in decoding:
x = qr [2] [0] #Q2码的左侧位置
qr_dic [x] = qr [0]#存储在QR码中的数据
for qr in sorted(qr_dic.keys()):
print(qr_dic [qr] ])
输出:
b'url1'
b'url2'
b'url3'
b'url4'
b'url5'
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.
解决方案
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'
这篇关于如何在单独的图像中拆分qr代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!