YOLOv8计数值

问题描述 投票:0回答:1

我正在开发一个项目,当他检测到车辆时,他会计算道路上的车辆数量,而无需使用(yolo)画线。 enter image description here

我想在yolo中达到这个值(3辆车)? 对它进行一些操作并显示它,有人可以帮助我吗?

python yolo yolov8
1个回答
0
投票

要从结果中获取相同类对象的计数,您需要在

model.names
中获取该类的 id,并统计该值在
results[0].boxes.data[:, -1]
中出现的次数(获取图像中所有检测到的对象并获取他们的 class_ids)。

# define the model
model = YOLO('yolov8s.pt')
# run inference on the source image
results = model('image.jpg')
# get the model names list
names = model.names
# get the 'car' class id
car_id = list(names)[list(names.values()).index('car')]
# count 'car' objects in the results
results[0].boxes.data[:,-1].tolist().count(car_id)
© www.soinside.com 2019 - 2024. All rights reserved.