检测detect.py修改与运行笔记2:找出文件夹中所有图片的**

博客主要讲述使用Python结合YOLOv5进行逐个文件夹的物体检测,并对检测结果进行处理。检测涉及80个类别,若图片中未检测到物体,无txt记录但有图片记录。
部署运行你感兴趣的模型镜像

逐个文件夹运行检测


import os
import cv2
path = '/home/fly100/fsdownload'
filelist = os.listdir(path)

for item in filelist:
    print(item)
    os.system("python detect.py --weights yolov5s.pt --img 640 --conf 0.7 --name "+str(item)+" "+"--source /home/fly100/fsdownload/"+str(item))

结果处理

  • 80个类别
['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush']

在这里插入图片描述

在这里插入图片描述

import os
import cv2



def finddog(dirname,path):
    filelist = os.listdir(path)
    filelist.sort(key= lambda x:int(x[:-4]))


    for item in filelist:
        if item.endswith('.txt'):
            import  time
            time.sleep(0.1)

            f = open(os.path.join(path, item), encoding="utf-8")
            a = f.read().split('\n')
            for i in range(len(a)-1):# 最后一个是空的
                b = a[i].split(' ')[0]
                if b == str(16):
                    print(item)
                    print(int(item[:-4]))
                    print(a[i].split(' ')[5])

            f.close()# 关闭文件




head_path = '/home/fly100/myproject/yolov5/runs/detect/'
head_filelist = os.listdir(head_path)
for dirname in head_filelist:
    print(os.path.join(head_path, dirname,'labels'))
    path = os.path.join(head_path, dirname,'labels')
    finddog(dirname,path)


  • 运行结果:
/home/fly100/myproject/yolov5/runs/detect/test/labels
103029.txt
103029
0.748119
109055.txt
109055
0.720829
230063.txt
230063
0.914511

在这里插入图片描述在这里插入图片描述

注:如果在一张图片中没有检测到任何物体,那么不会有txt的记录,但是会有图片的记录

您可能感兴趣的与本文相关的镜像

Yolo-v5

Yolo-v5

Yolo

YOLO(You Only Look Once)是一种流行的物体检测和图像分割模型,由华盛顿大学的Joseph Redmon 和Ali Farhadi 开发。 YOLO 于2015 年推出,因其高速和高精度而广受欢迎

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值