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

逐个文件夹运行检测


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的记录,但是会有图片的记录

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值