seqinfo.ini的内容,相当于对该数据集的说明描述
[Sequence]
name=MOT16-04
imDir=img1
frameRate=30
seqLength=1050
imWidth=1920
imHeight=1080
imExt=.jpg
seqLength 表示 序列的长度,也就是帧的总数1050
图片大小是1920 × 1080
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
加个列标题
, < Track ID>, , , , , , , ,
0、Frame ID 表示帧ID。
1、Track ID 表示这个object属于哪个track 。每个object只能被分配到一个track,-1表示未分配。
2、3、4、5、接下来的四个数字表示行人在二维图像坐标中的边界框位置。位置由左上角以及边框的宽度和高度表示(无归一化)。
6、confidence score, 置信度。
最后三个7、 8、 9都是-1,xyz,具体怎么用,未知。
就像数据库里面的表,表达一对多的关系。
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
加个列标题
,
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的可见程度。
# -*- 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()