本文主要是在推理detect阶段,预测的图片或视频中没有标签的数量统计
在 detect.py中的第171行(大家看自己位置,我这里是大概位置)加入这行代码
cv2.putText(im0, f"{n} " + 'person', (5, 50), cv2.FONT_HERSHEY_SIMPLEX, 1.2, (0, 0, 255), 2)
修改后的 11行和28行29行
if len(det):
# Rescale boxes from img_size to im0 size
det[:, :4] = scale_coords(im.shape[2:], det[:, :4], im0.shape).round()
# Print results
for c in det[:, -1].unique():
n = (det[:, -1] == c).sum() # detections per class
print(n)
s += f"{n} {names[int(c)]}{'s' * (n > 1)}, " # add to string
cv2.putText(im0, f"{n} " +