import cv2
detector = cv2.wechat_qrcode_WeChatQRCode('detect.prototxt', 'detect.caffemodel', 'sr.prototxt', 'sr.caffemodel')
img = cv2.imread('img.jpg')
res, points = detector.detectAndDecode(img)
print(res, points)
微信扫码引擎收录于:
opencv_contrib/modules/wechat_qrcode
开发文档:
https://docs.opencv.org/master/d5/d04/classcv_1_1wechat__qrcode_1_1WeChatQRCode.html
微信扫码引擎是一款基于开源引擎ZXing,并高度优化和深度改造的高性能轻量二维码识别器。
1. 基于CNN的二维码检测
“一图多码”是扫码支付经常遇到的线下场景。早在2016年,微信扫码引擎在业内率先支持远距离二维码检测、自动调焦定位、多码检测识别。然而,传统方法需要牺牲40%以上的性能来支持多码的检测与识别。伴随着深度学习技术的成熟和移动端计算能力的提升,微信扫码引擎引入基于CNN的二维码检测器解决上述问题。
图1 二维码检测器
我们以SSD框架为基础,构造了短小精干的二维码检测器(图1),采用残差连接(Residual Concat)、深度卷积(Depthwise Convolution)、空洞卷积(Dilated Convolution)、卷积投影(Convolution Projection)等技术进行了针对性的优化。整个模型大小仅943KB,iPhone7(A10)单CPU的推理时间仅需20ms,很好地满足“低延时、小体积、高召回”的业务需求。
检测代码:
https://github.com/opencv/opencv_contrib/blob/master/modules/wechat_qrcode/src/wechat_qrcode.cpp#L156
模型文件:
https://github.com/WeChatCV/opencv_3rdparty/blob/wechat_qrcode/detect.prototxt
参数文件:
https://github.com/WeChatCV/opencv_3rdparty/blob/wechat_qrcode/detect.caffemodel
联系客服