将Yolov5的检测结果文本输出格式改成MOT17格式

先说一下Yolov5的格式:

检测文本输出格式也是标注格式:1、类   2、检测框中心点x值  3、中心点y值    4、宽   5、高     6、置信度    (2,3,4,5均为归一化后的值)

如果是视频会把每一帧都建立一个TXT。

MOT17格式:

       

1、帧    2、对象ID    3、左上角点的X    4、左上角Y      5、宽    6、高     7、置信度     8、9、10分别为xyz,2D用不着。

总共要改两处地方(注释掉的为原来的代码):

  # 设置保存框坐标txt文件的路径
            #txt_path = str(save_dir / 'labels' / p.stem) + ('' if dataset.mode == 'image' else f'_{frame}')  # img.txt
            #MOT17格式
            txt_path = str(save_dir / 'labels' / p.stem)









# if save_txt:  # Write to file
                    #     # 将xyxy(左上角+右下角)格式转为xywh(中心点+宽长)格式,并除上w,h做归一化,转化为列表再保存
                    #     xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist()  # normalized xywh
                    #     line = (cls, *xywh, conf) if opt.save_conf else (cls, *xywh)  # label format
                    #     with open(txt_path + '.txt', 'a') as f:
                    #         f.write(('%g ' * len(line)).rstrip() % line + '\n')
                    if save_txt:  #重写成mot17格式的输出
                        xywh = xyxy2xywh(torch.tensor(xyxy).view(1, 4))
                        line = (frame,-1, xyxy[0],xyxy[1],xywh[:,2],xywh[:,3],conf,-1,-1,-1)
                        with open(txt_path + '.txt', 'a') as f:
                            f.write(('%g,' *(len(line)-1)+'%g').rstrip() % line + '\n')

  顺便一提 gt格式:

  • 5
    点赞
  • 39
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值