Yolo目标检测标注格式转换成多目标跟踪数据集MOT标注格式

1. 多目标跟踪 Deep SORT 数据集MOT说明

(1)概况

seqinfo.ini的内容,相当于对该数据集的说明描述
[Sequence]
name=MOT16-04
imDir=img1
frameRate=30
seqLength=1050
imWidth=1920
imHeight=1080
imExt=.jpg

seqLength 表示 序列的长度,也就是帧的总数1050
图片大小是1920 × 1080

(2)输入det.txt (detection)

1,-1,97,545,79,239,3.1667,-1,-1,-1
1,-1,369,401,79,239,3.1112,-1,-1,-1
1,-1,546.66,146.51,59.629,180.89,2.686,-1,-1,-1
1,-1,1638,255.64,59.629,180.89,2.6417,-1,-1,-1
1,-1,1043.8,134.38,59.629,180.89,2.3391,-1,-1,-1
1,-1,792.96,148.08,55.569,168.71,2.2532,-1,-1,-1
1,-1,1742.1,460.65,68.644,207.93,2.1848,-1,-1,-1
1,-1,1104.4,207.14,59.629,180.89,1.9684,-1,-1,-1
1,-1,498.16,122.26,59.629,180.89,1.4027,-1,-1,-1
1,-1,906.1,125.45,55.569,168.71,1.2634,-1,-1,-1
1,-1,351.89,91.972,63.98,193.94,1.1681,-1,-1,-1
1,-1,222.68,127.67,51.78,157.34,0.97654,-1,-1,-1

加个列标题

<Frame ID>, < Track ID>, <bb_left>, <bb_top>, <bb_width>, <bb_height>, <Confidence score>, <x>, <y>, <z>

0、Frame ID 表示帧ID。
1、Track ID 表示这个object属于哪个track 。每个object只能被分配到一个track,-1表示未分配。
2、3、4、5、接下来的四个数字表示行人在二维图像坐标中的边界框位置。位置由左上角以及边框的宽度和高度表示(无归一化)。
6、confidence score, 置信度。
最后三个7、 8、 9都是-1,xyz,具体怎么用,未知。
就像数据库里面的表,表达一对多的关系。

(3)输出gt.txt (annotation/ground truth (GT) )

1,1,1363,569,103,241,1,1,0.86014
2,1,1362,568,103,241,1,1,0.86173
3,1,1362,568,103,241,1,1,0.86173
4,1,1362,568,103,241,1,1,0.86173
5,1,1362,568,103,241,1,1,0.86173
6,1,1362,568,103,241,1,1,0.86173
7,1,1362,568,103,241,1,1,0.86173
8,1,1362,568,103,241,1,1,0.86173
9,1,1362,568,103,241,1,1,0.86173
10,1,1362,568,103,241,1,1,0.86173

加个列标题

<Frame ID>, <Track ID>, <bb_left>, <bb_top>, <bb_width>, <bb_height>, <0/1> ,<Class ID> ,<Visibility Ratio>

0、Frame ID
1、Track ID
2、3、4、5 bbox坐标(x, y, w, h)
6、是否考虑 the entry,flag: considered (1) , ignored (0)
7、标注对象的类别
9、可见比例(visibility ratio),因为object的遮挡和图像边框裁剪,用一个介于0和1之间的数字表示该object的可见程度。

2. yolo标签txt转MOT标签det和gt程序

# -*- coding:utf8 -*-
from PIL import Image
import os
import glob
import numpy as np

def txt2det(yolo_labels_dir, mot_labels_det_path):
    object_id = 1  # 目标ID
    with open(mot_labels_det_path, 'w') as mot_file:
        for file in os.listdir(yolo_labels_dir):
            if file.endswith(".txt"):
                yolo_file_path = os.path.join(yolo_labels_dir, file)
                frame_idx = int(file.split("_")[-1].split(".")[0])  # 提取帧索引
                image_width = 1280
                image_height=720

                with open(yolo_file_path, 'r') as yolo_file:
                    lines = yolo_file.readlines()

                    for line in lines:
                        data = line.split()
                        class_id = int(data[0])
                        x_center = float(data[1])
                        y_center = float(data[2])
                        width = float(data[3])
                        height = float(data[4])

                        left = int((x_center - width / 2) * image_width)
                        top = int((y_center - height / 2) * image_height)
                        # right = int((x_center + width / 2) * image_width)
                        # bottom = int((y_center + height / 2) * image_height)
                        w = int(width*image_width)
                        h = int(height * image_height)

                        # 写入MOT标签文件
                        mot_file.write("{},-1,{},{},{},{},1,-1,-1,-1\n".format(frame_idx, left, top, w, h))
                object_id += 1

def txt2gt(yolo_labels_dir, mot_labels_gt_path):
    object_id = 1  # 目标ID
    with open(mot_labels_gt_path, 'w') as mot_file:
        for file in os.listdir(yolo_labels_dir):
            if file.endswith(".txt"):
                yolo_file_path = os.path.join(yolo_labels_dir, file)
                frame_idx = int(file.split("_")[-1].split(".")[0])  # 提取帧索引
                image_width = 1280
                image_height=720

                with open(yolo_file_path, 'r') as yolo_file:
                    lines = yolo_file.readlines()

                    for line in lines:
                        data = line.split()
                        class_id = int(data[0])
                        x_center = float(data[1])
                        y_center = float(data[2])
                        width = float(data[3])
                        height = float(data[4])

                        left = int((x_center - width / 2) * image_width)
                        top = int((y_center - height / 2) * image_height)
                        # right = int((x_center + width / 2) * image_width)
                        # bottom = int((y_center + height / 2) * image_height)
                        w = int(width*image_width)
                        h = int(height * image_height)

                        # 写入MOT标签文件
                        mot_file.write("{},{},{},{},{},{},0,{},1\n".format(frame_idx,object_id,left, top, w, h,class_id))
                object_id += 1

def main():
    # 设置YOLO标签文件夹和MOT标签文件路径
    yolo_labels_dir = "/yolo_txt"
    mot_labels_det_path = "/mot_det.txt"
    mot_labels_gt_path = "/mot_gt.txt"
    # 调用转换函数
    txt2det(yolo_labels_dir, mot_labels_det_path)
    txt2gt(yolo_labels_dir, mot_labels_gt_path)

if __name__ == '__main__':
    main()


  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
目标检测图片已标注YOLO格式数据集可以在以下地方进行下载: 1. Kaggle(https://www.kaggle.com/):Kaggle是一个数据科学竞赛平台,提供各种数据集供用户下载。在Kaggle的数据集页面上,你可以通过搜索相关关键词或者浏览不同的目录来找到YOLO格式数据集。选择适合你需求的数据集后,你可以通过点击下载按钮来获取数据集。 2. GitHub(https://github.com/):GitHub是一个源代码托管平台,很多开发者和研究者会在上面分享自己的数据集。你可以在GitHub上搜索关键词加上"YOLO dataset"或者"YOLO format dataset"来查找相应的数据集。当找到合适的仓库时,你可以在仓库的页面上找到数据集的下载链接或者通过克隆仓库来获取数据集。 3. Open Images Dataset(https://storage.googleapis.com/openimages/web/index.html):Open Images Dataset是一个由Google提供的大规模图像数据集,其中包括了一些已经标注目标检测数据。你可以在官方网站上找到YOLO格式数据集,并通过点击下载按钮来获取数据集。 4. 研究论文和竞赛网站:一些研究论文或者目标检测竞赛网站会提供YOLO格式数据集供用户下载。常见的论文网站有arXiv(https://arxiv.org/)和CVPR(https://openaccess.thecvf.com/CVPR2021)。常见的竞赛网站有COCO数据集(http://cocodataset.org/)和ImageNet(http://www.image-net.org/)。你可以在这些网站上找到相关的数据集下载链接。 需要注意的是,不同的数据集可能具有不同的许可证要求,所以在下载和使用数据集时,请查阅相关的许可证信息,并遵守相关的规定。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值