逐个文件夹运行检测
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的记录,但是会有图片的记录
博客主要讲述使用Python结合YOLOv5进行逐个文件夹的物体检测,并对检测结果进行处理。检测涉及80个类别,若图片中未检测到物体,无txt记录但有图片记录。
5589

被折叠的 条评论
为什么被折叠?



