二维码和条形码包含很多信息,对二维码和条形码识别对信息抽取具有重要意义。下面介绍两种二维码识别的方法,并用python实现。
import os
import cv2
from cv2.wechat_qrcode import WeChatQRCode
from pyzbar import pyzbar
import time
"""
sudo apt-get install libzbar-dev
pip install zbar
"""
fream = cv2.imread("test.png")
start=time.time()
for i in range(1000):
decocdeQR = pyzbar.decode(fream)
res = decocdeQR[0].data.decode('utf-8')
end = time.time()
print("time:", end-start)
print("zbar的识别结果:")
print(res)
detector = WeChatQRCode(detector_prototxt_path="qr_mode/detect.prototxt",
detector_caffe_model_path="qr_mode/detect.caffemodel",
super_resolution_prototxt_path="qr_mode/sr.prototxt",
super_resolution_caffe_model_path="qr_mode/sr.caffemodel")
img = cv2.imread("test.png")
start=time.time()
for i in range(1000):
res, points = detector.detectAndDecode(img)
end=time.time()
print("time:", end-start)
print("微信的识别结果:")
print(res)
在终端的显示如下:
time: 2.875035285949707
zbar的识别结果:
http://fs.hncz.gov.cn:8094//EivcCheckH5?payer=螳牙サカ邇イ&ivccode=41060223&ivcno=0000555268&ckno=2bae01
time: 3.0192439556121826
微信的识别结果:
('http://fs.hncz.gov.cn:8094//EivcCheckH5?payer=安延玲&ivccode=41060223&ivcno=0000555268&ckno=2bae01',)
从上面的结果可以看到,加上博主的大量测试,得出以下结论: