# 批量二维码读取
import cv2 as cv
import pyzbar.pyzbar as pbar
import os
import numpy as np
import pandas as pd
#二维码存在路径
filepath = "..\\opencv\\cod3\\"
#获取二维码名称
img = os.listdir(filepath)
#读取二维码,存放在列表中读取结果
list1 = []
list2 = []
for i in img:
try:
image = cv.imread("..\\opencv\\cod3\\"+i)
barcodes =pbar.decode(image)
code = barcodes[0]
code_data = code.data.decode('utf-8')
data = code_data.split("=")
list1.append([i,str(data[1])[:32]])
# print(i,":",str(data[1])[:30],"\n")
except IndexError:
# print(i,":","读取失败")
list2.append([i,"读取失败"])
print("*"*50)
print('共计有',len(img),'个二维码')
print(len(list1),"个二维码识别成功")
print(len(list2),"个二维码识别失败")
print("*"*50)
#三种方法将读取结果写入文件
#方法一:写入txt文件
# 将读取结果写到txt文件中
de
批量读取二维码
于 2022-06-30 14:28:45 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)