import cv2 import numpy as np cap = cv2.VideoCapture(0) while True: ret, frame = cap.read() detector = cv2.wechat_qrcode_WeChatQRCode("detect.prototxt", "detect.caffemodel", "sr.prototxt", "sr.caffemodel") res, points = detector.detectAndDecode(frame) for one_pt in points: one_pt = np.array(one_pt, dtype=np.int) cv2.polylines(frame, [one_pt], isClosed=True, color=(255, 0, 0), thickness=3) print('条码信息:', res) cv2.imshow("cap", frame) if cv2.waitKey(100) & 0xff == ord('q'): break cap.release() cv2.destroyAllWindows() 调用微信开源库进行二维码的检测和识别 import cv2 import numpy as np cap = cv2.VideoCapture(0) while True: ret, frame = cap.read() detector = cv2.wechat_qrcode_WeChatQRCode("detect.prototxt", "detect.caffemodel", "sr.prototxt", "sr.caffemodel") res, points = detector.detectAndDecode(frame) for one_pt in points: one_pt = np.array(one_pt, dtype=np.int) cv2.polylines(frame, [one_pt], isClosed=True, color=(255, 0, 0), thickness=3) print('条码信息:', res) cv2.imshow("cap", frame) if cv2.waitKey(100) & 0xff == ord('q'): break cap.release() cv2.destroyAllWindows()
汉字 字母均可识别生成 opencv的zbar库只能识别生成字母 如果二维码封存的是汉字 则zbar会乱码
开源库下载链接
链接:https://pan.baidu.com/s/1aYNJ8ukV8qraOQuiiIwG-Q
提取码:apbo
将开源库内文件放在跟代码同级的目录即可