python 二维码检测-
参考文章:
使用微信扫一扫二维码接口解密QRcode - 知乎 (zhihu.com)
import cv2 import numpy as np import os def open_img(img_dir): img_list = [] for _,_,file_list in os.walk(img_dir): img_list = [os.path.join(img_dir,file) for file in file_list if file.endswith(".jpg") or file.endswith(".png") ] #print("所有文件:{}".format(img_list)) return img_list def show(image_path): detector = cv2.wechat_qrcode_WeChatQRCode("detect.prototxt", "detect.caffemodel", "sr.prototxt", "sr.caffemodel") img = cv2.imread(image_path) if img is None: #print(f'{image_path}图片打开异常,原始格式不正确') return False res, points = detector.detectAndDecode(img) if res: print(f'{image_path}图片含二维码') return True return False def img_type_check(path): #jpg,gif,png... f = open(path,'rb') content = f.read() return content[:10] if __name__ == '__main__': #单文件判断 img_path = './image/88.jpg' show(img_path) #批量路径判断 for im in open_img('E:\\jupyter_wsp\\opencv_3rdparty-wechat_qrcode\\image\\'): _ = show(im)
#图像为空的原因可能是文件格式改变了,使用
#img_type_check(path)检测,比如命名为jpg,实际是gif文件。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
2020-11-01 python – 解析pcfg语法树 提取其语法规则 Probabilistic Context-Free Grammar Parser