python pyzbar 批量识别二维码

1、安装pyzbar

pip install pyzbar

2、代码

import os
import cv2 as cv
from pyzbar import pyzbar

# 目录路径
path = "D:\data_img"
data = [];

file_list = os.listdir(path)
for file in file_list:

    if not file.endswith(".jpg"):
        continue

    cur_path = os.path.join(path, file)
    # print(cur_path)

    img = cv.imread(cur_path)
    barcodes = pyzbar.decode(img)
    for barcode in barcodes:
        #print(file + ":" + bytes.decode(barcode.data));
        data.append(file + ":" + bytes.decode(barcode.data))

with open(path + "\data.txt", "w") as f:
    for item in data:
        # print(item)
        f.write(item+'\n')

你可能感兴趣的:(python,python,windows)