当前位置:   article > 正文

Yolov5根据目标类别自定义识别框的颜色_yolov5识别颜色

yolov5识别颜色

修改下detect文件下的write results函数

  1. # Write results
  2. for *xyxy, conf, cls in reversed(det):
  3. if save_txt: # Write to file
  4. xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
  5. line = (cls, *xywh, conf) if opt.save_conf else (cls, *xywh) # label format
  6. with open(txt_path + '.txt', 'a') as f:
  7. f.write(('%g ' * len(line)).rstrip() % line + '\n')
  8. if save_img or view_img: # Add bbox to image
  9. label = f'{names[int(cls)]} {conf:.2f}'
  10.     #定义颜色
  11. color_dict = {'1': [0, 0, 250], '2': [190, 90, 92], '3': [142, 154, 78], '4': [2, 76, 82],
  12. '5': [119, 80, 5], '6': [189, 163, 234]} # Rgb3个值:B G R
  13. if names[int(cls)] == 'car':        #根据训练的文件.yaml中的name类中的名称修改
  14. color_single = color_dict['1']
  15. elif names[int(cls)] == 'person':       
  16. color_single = color_dict['2']
  17. plot_one_box(xyxy, im0, label=label, color=color_single, line_thickness=3)

参考文档:

(53条消息) 【目标检测】YOLOv5:标签中文显示/自定义颜色_yolov5中文标签_zstar-_的博客-CSDN博客

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/997800
推荐阅读
相关标签
  

闽ICP备14008679号