微信二维码检测器是微信计算机视觉团队(微信)提供的一款高性能、轻量级的二维码检测和解码库。 已广泛应用于微信、WeCom、QQ、QQ浏览器等腾讯应用中。目前这个功能已经集成到opencv_contrib模块,使用十分方便。

开源地址:https://github.com/opencv/opencv_contrib/tree/4.x/modules/wechat_QRCode

安装和使用非常简单

1. 安装: pip install opencv-python pip install opencv-contrib-python 2. 如下地址下载四个模型文件:detect.prototxt, detect.caffemodel, sr.prototxt, sr.caffemodel: https://github.com/Tianxiaomo/qrDecoder/tree/master/model

如下是例子,更详细的例子可以参看项目中的samples/qrcode.py,里面包含调用摄像头的例子:

import cv2 detector = cv2.wechat_qrcode_WeChatQRCode("detect.prototxt", "detect.caffemodel", "sr.prototxt", "sr.caffemodel") img = cv2.imread("qrcode.jpg") # 包含二维码的图片 res, points = detector.detectAndDecode(img) print(res, points)

微信开发者工具扫描二维码(微信二维码识别库wechat)(1)

,