对图像的识别 识别后用列表进行对比

使用OpenCV库,遍历指定文件夹中的.jpg, .png, .jpeg图片,识别其中的二维码内容并存储到列表中。若发现重复的二维码,打印相关信息。最后输出识别的图片数量。" 101151092,5650088,Linux中复制文件的多种方法,"['Linux', '文件操作', '命令行工具', '文件复制', '终端命令']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import cv2
import os

folder_path = r'C:\Users\ohnb\Desktop\tu\tugai'

qr_codes = []  # 存储二维码内容的列表

tus=0
# 识别图片的数量
for filename in os.listdir(folder_path):
    tus=tus+1
    file_path = os.path.join(folder_path, filename)
    if filename.endswith('.jpg') or filename.endswith('.png') or filename.endswith('.jpeg'):
        img = cv2.imread(file_path)
        detector = cv2.QRCodeDetector()
        data, bbox, _ = detector.detectAndDecode(img)
        if bbox is not None:
            if data in qr_codes:
                print(f'二维码存在相同 "{data}" 文件名: "{filename}"')
            else:
                # print(f'二维码内容 "{data}" 文件名: "{filename}"')
                # 输出二维码内容
                qr_codes.append(data)

print("本次识别的图片数量为:",tus)
if not qr_codes:
    print('No QR codes found in the folder.')
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq_58758353

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值