参考文章:

使用微信扫一扫二维码接口解密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文件。

 

原文地址:http://www.cnblogs.com/cupleo/p/16848157.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性