参考文章:
使用微信扫一扫二维码接口解密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文件。
标签:return,img,python,检测,image,list,二维码,file,path From: https://www.cnblogs.com/cupleo/p/16848157.html