这是在使用yolo+deepsort时候想要用不同的颜色来区分不同的人
版本v3.0有这个功能
但是我下载的版本v5.0是根据种类的不同来区分颜色的
针对只有一种种类的时候,就只能绘制一种颜色的框,不能有效的区分
所以记录一下。
GitHub地址 :v3.0版本:yolo+deepsort track.py
两种方法:
第一种是将本来根据不同标签生成不同颜色的改成不同id对应不同颜色的
但是这个方法不知道会不会因为目标过多而受限,因为他的颜色好像是一个固定的列表。。。
#annotator.box_label(bboxes, label, color=colors(c, True))
annotator.box_label(bboxes, label, color=colors(int(id), True))
第二种:
# 根据不同的id生成颜色
def compute_color_for_labels(label):
"""
Simple function that adds fixed color depending on the class
"""
color = [int((p * (label ** 2 - label + 1)) % 255) for p in palette]
return tuple(color)
#省略很多代码。。。。。。。
if save_vid or save_crop or show_vid: # Add bbox to image
c = int(cls) # integer class 这是根据种类来划分颜色的
id = int(id)
label = f'{id} {names[c]} {conf:.2f}'
# annotator.box_label(bboxes, label, color=colors(c, True))
color = compute_color_for_labels(id)
annotator.box_label(bboxes, label, color=color)