visdrone数据集转化为MOT数据集(用作MOTR模型训练)

visdrone数据集转化为MOT数据集

MOT17 数据集格式

├── MOT17
│   ├── images
│   ├── labels_with_ids

train

det.txt

10个参数 或者 8个参数

<frame>, <id>, <bb_left>, <bb_top>, <bb_width>, <bb_height>, <conf>, <x>, <y>, <z> 
  • 第1个代表第几帧
  • 第2个代表轨迹编号(在这个文件里总是为-1)
  • bb开头的4个数代表物体框的左上角坐标及长宽
  • conf代表置信度
  • 最后3个是MOT3D用到的内容,2D检测总是为-1.

在这里插入图片描述

gt.txt

9个参数

  • 第1个代表第几帧
  • 第2个值为目标运动轨迹的ID号
  • 第3个到第6个数代表物体框的左上角坐标及长宽
  • 第7个值为目标轨迹是否进入考虑范围内的标志,0表示忽略,1表示active
  • 第8个值为该轨迹对应的目标种类(种类见下面的表格中的label-ID对应情况)
  • 第9个值为box的visibility ratio,表示目标运动时被其他目标box包含/覆盖或者目标之间box边缘裁剪情况。

在这里插入图片描述

seqinfo.ini

主要介绍视频的帧率、分辨率等基本信息。

在这里插入图片描述

test

det.txt

数据标签含义与train相同。

在这里插入图片描述

visdrone——Task 4_ Multi-Object Tracking

    <frame_index>,<target_id>,<bbox_left>,<bbox_top>,<bbox_width>,<bbox_height>,<score>,<object_category>,<truncation>,<occlusion>

 -----------------------------------------------------------------------------------------------------------------------------------
       Name	                                      Description
 -----------------------------------------------------------------------------------------------------------------------------------
   <frame_index>	  The frame index of the video frame
   
    <target_id>	          In the DETECTION result file, the identity of the target should be set to the constant -1.
		          In the GROUNDTRUTH file, the identity of the target is used to provide the temporal corresponding 
		          relation of the bounding boxes in different frames.
			  
    <bbox_left>	          The x coordinate of the top-left corner of the predicted bounding box

    <bbox_top>	          The y coordinate of the top-left corner of the predicted object bounding box

    <bbox_width>	  The width in pixels of the predicted object bounding box

    <bbox_height>	  The height in pixels of the predicted object bounding box

      <score>	          The score in the DETECTION file indicates the confidence of the predicted bounding box enclosing 
                          an object instance.
                          The score in GROUNDTRUTH file is set to 1 or 0. 1 indicates the bounding box is considered in evaluation, 
		          while 0 indicates the bounding box will be ignored.
			  
  <object_category>	  The object category indicates the type of annotated object, (i.e., ignored regions(0), pedestrian(1), 
                          people(2), bicycle(3), car(4), van(5), truck(6), tricycle(7), awning-tricycle(8), bus(9), motor(10), 
                          others(11))
		      
    <truncation>	  The score in the DETECTION file should be set to the constant -1.
                          The score in the GROUNDTRUTH file indicates the degree of object parts appears outside a frame 
		          (i.e., no truncation = 0 (truncation ratio 0%), and partial truncation = 1 (truncation ratio 1% ~ 50%)).
		      
     <occlusion>	  The score in the DETECTION file should be set to the constant -1.
                          The score in the GROUNDTRUTH file indicates the fraction of objects being occluded 
		          (i.e., no occlusion = 0 (occlusion ratio 0%), partial occlusion = 1 (occlusion ratio 1% ~ 50%), 
		          and heavy occlusion = 2 (occlusion ratio 50% ~ 100%)).
├── visdrone
│   ├── images
│   │   ├── train
│   │   │   ├── 视频目录
│   │   │   │   ├── gt
│   │   │   │   ├── img1
│   │   │   │   ├── seqinfo.ini
│   │   ├── test
│   ├── labels_with_ids
│   

配置seqinfo.ini文件

[Sequence]
name=MOT17-02-DPM
imDir=img1
frameRate=30
seqLength=600
imWidth=1920
imHeight=1080
imExt=.jpg

其中,imWidth、imHeight、imExt分别为图片的宽、高、格式;seqLength表示此视频被抽成了多少帧。frameRate为画面更新率。

代码如下

import os
import shutil
from tqdm import tqdm
from PIL import Image


def copyfile(old_folder_path,new_folder_path):
    print('---------------------')
    for file in os.listdir(old_folder_path):
        old_file_path=os.path.join(old_folder_path,file)
        # print(file)
        # print(new_folder_path)
        shutil.copy(old_file_path, new_folder_path)

def makedir(filepath):
    if not os.path.exists(filepath):
        os.mkdir(filepath)

def process(path):
    annotations_path = os.path.join(path, "annotations")
    ann_set = os.listdir(annotations_path)
    # print(ann_set)
    file_path=os.path.join(path,'sequences')
    file_set=os.listdir(file_path)
    # print(file_set)
    for i in tqdm(ann_set):
        f = open(annotations_path + "/" + i, "r")
        print(i)
        name = i.replace(".txt", "")
        print(name)
        img_path=os.path.join(file_path,name)
        img_set=os.listdir(img_path)
        img=Image.open(os.path.join(img_path,img_set[0]))
        for line in f.readlines():
            line = line.replace("\n", "")
            if line.endswith(","):  # filter data
                line = line.rstrip(",")
            line_list = [int(i) for i in line.split(",")]
            new_line_list=[line_list[i] for i in range(0,8)]
            print(line_list)
            # print(new_line_list)
            if(line_list[8]==0 and line_list[9]==0):
                new_line_list.append(1)
            if (line_list[8] == 0 and line_list[9] == 1):
                new_line_list.append(0.9)
            if (line_list[8] == 1 and line_list[9] == 0):
                new_line_list.append(0.8)
            if (line_list[8] == 0 and line_list[9] == 2):
                new_line_list.append(0.7)
            if (line_list[8] == 1 and line_list[9] == 1):
                new_line_list.append(0.5)
            if (line_list[8] == 1 and line_list[9] == 2):
                new_line_list.append(0.3)
            # print(new_line_list)
            url1 = os.path.join(path,name)
            makedir(url1)
            url2=os.path.join(name,'gt')
            makedir(url2)
            file_url=url2+'\\gt.txt'
            print(url2)
            print(file_url)
            if not os.path.isfile(file_url):
                fd = open(file_url, mode="w", encoding="utf-8")
            makedir(file_url)
            with open(file_url, 'a') as file_name:
                str_text = str(new_line_list[0]) + ',' + str(new_line_list[1]) + ',' + str(new_line_list[2]) + ',' + str(
                    new_line_list[3]) + ',' + str(new_line_list[4]) + ',' + str(new_line_list[5]) + ',' + str(
                    new_line_list[6]) + ',' + str(new_line_list[7])+ ',' + str(new_line_list[8])
                print(str_text)
                file_name.write(str_text + '\n')

        ini_path = os.path.join(path, name)
        ini_file=ini_path+'\\seqinfo.ini'
        print('***********************************')
        if not os.path.isfile(ini_file):
            fd = open(ini_file, mode="w", encoding="utf-8")
        with open(ini_file, 'a') as ini_name:
            ini_text ='[Sequence]\n'+'name='+name+'\n'+'imDir=img1\n'+'frameRate=30\n'+'seqLength='+str(len(img_set))+'\n'+'imWidth = '+str(img.size[0])+'\n'+'imHeight = '+str(img.size[1])+'\n'+'imExt =.jpg\n'
            print(ini_text)
            ini_name.write(ini_text + '\n')
        break
    old_path=os.path.join(file_path,name)
    new_path=os.path.join(path,name,'img1')
    print(old_path)
    print(new_path)
    move(old_path,new_path)

def move(old_path,new_path):
    makedir(new_path)
    copyfile(old_path,new_path)

if __name__ == '__main__':
    path1=r'D:\pythonProjects\Test\visdrone2mot\annotations'
    path2=r'D:\pythonProjects\Test\visdrone2mot\sequences'
    path=r'D:\pythonProjects\Test\visdrone2mot'
    process(path)

Linux

import os
import shutil
from tqdm import tqdm
from PIL import Image


def copyfile(old_folder_path,new_folder_path):
    print('---------------------')
    for file in os.listdir(old_folder_path):
        old_file_path=os.path.join(old_folder_path,file)
        # print(file)
        # print(new_folder_path)
        shutil.copy(old_file_path, new_folder_path)

def makedir(filepath):
    if not os.path.exists(filepath):
        os.mkdir(filepath)

def process(path):
    annotations_path = os.path.join(path, "annotations")
    ann_set = os.listdir(annotations_path)
    # print(ann_set)
    file_path=os.path.join(path,'sequences')
    file_set=os.listdir(file_path)
    # print(file_set)
    for i in tqdm(ann_set):
        f = open(annotations_path + "/" + i, "r")
        print(i)
        name = i.replace(".txt", "")
        print(name)
        img_path=os.path.join(file_path,name)
        img_set=os.listdir(img_path)
        img=Image.open(os.path.join(img_path,img_set[0]))
        old_path = os.path.join(file_path, name)
        new_path = os.path.join(path, name, 'img1')
        print(old_path)
        print(new_path)
        move(old_path, new_path)
        for line in f.readlines():
            line = line.replace("\n", "")
            if line.endswith(","):  # filter data
                line = line.rstrip(",")
            line_list = [int(i) for i in line.split(",")]
            new_line_list=[line_list[i] for i in range(0,8)]
            print(line_list)
            # print(new_line_list)
            if(line_list[8]==0 and line_list[9]==0):
                new_line_list.append(1)
            if (line_list[8] == 0 and line_list[9] == 1):
                new_line_list.append(0.9)
            if (line_list[8] == 1 and line_list[9] == 0):
                new_line_list.append(0.8)
            if (line_list[8] == 0 and line_list[9] == 2):
                new_line_list.append(0.7)
            if (line_list[8] == 1 and line_list[9] == 1):
                new_line_list.append(0.5)
            if (line_list[8] == 1 and line_list[9] == 2):
                new_line_list.append(0.3)
            # print(new_line_list)
            url1 = os.path.join(path,name)
            makedir(url1)
            print('url1:',url1)
            url2=os.path.join(url1,'gt')
            print('url2:',url2)
            makedir(url2)
            file_url=url2+'/gt.txt'
            print(url2)
            print(file_url)
            if not os.path.isfile(file_url):
                fd = open(file_url, mode="w", encoding="utf-8")
            makedir(file_url)
            with open(file_url, 'a') as file_name:
                str_text = str(new_line_list[0]) + ',' + str(new_line_list[1]) + ',' + str(new_line_list[2]) + ',' + str(
                    new_line_list[3]) + ',' + str(new_line_list[4]) + ',' + str(new_line_list[5]) + ',' + str(
                    new_line_list[6]) + ',' + str(new_line_list[7])+ ',' + str(new_line_list[8])
                print(str_text)
                file_name.write(str_text + '\n')

        ini_path = os.path.join(path, name)
        ini_file=ini_path+'/seqinfo.ini'
        print('***********************************')
        if not os.path.isfile(ini_file):
            fd = open(ini_file, mode="w", encoding="utf-8")
        with open(ini_file, 'a') as ini_name:
            ini_text ='[Sequence]\n'+'name='+name+'\n'+'imDir=img1\n'+'frameRate=30\n'+'seqLength='+str(len(img_set))+'\n'+'imWidth = '+str(img.size[0])+'\n'+'imHeight = '+str(img.size[1])+'\n'+'imExt =.jpg\n'
            print(ini_text)
            ini_name.write(ini_text + '\n')
        # break
      

def move(old_path,new_path):
    makedir(new_path)
    copyfile(old_path,new_path)

if __name__ == '__main__':
    path='/home/course/ldw/dataset/VisDrone2019-MOT-val/'
    process(path)
VisDrone2019-MOT数据集通常用于单目标跟踪任务,而YOLO(You Only Look Once)是一种用于物体检测的任务。将MOT数据转换成YOLO所需的标注文件,需要两个步骤:首先,从原始MOT数据中提取出每个帧的目标位置信息;然后,按照YOLO的数据格式规则组织这些信息。 由于这涉及到的具体编码工作通常涉及到图像处理库如OpenCV、Pandas等,并且会包含一些自定义脚本编写,这里提供一个简化的概述: 1. **读取和解析MOT数据**:使用Pandas或其他数据处理工具读取`.txt`格式的MOT跟踪数据,例如DataFrame可以存储每一帧的跟踪ID、框坐标和可能的其他属性。 ```python import pandas as pd def parse_mot_data(filename): df = pd.read_csv(filename, delimiter=' ', header=None) return df ``` 2. **格式化为YOLO所需**:YOLO数据格式通常是每行包含图片文件名、类别ID、x中心、y中心、宽度和高度。你需要提取出框的位置信息并添加必要的信息到新的CSV文件中。 ```python def mot_to_yolo(df, output_filename): df[['image_id', 'class', 'xmin', 'ymin', 'xmax', 'ymax']] = ... # 根据MOT数据结构填充新列 df[['image_id', 'class', 'center_x', 'center_y', 'width', 'height']] = ... # 计算YOLO所需的值 df.to_csv(output_filename, index=False) # 导出到csv ``` 注意,上述代码中的细节需要根据实际MOT数据结构进行调整。例如,`df[['image_id', 'class', ...]]`这部分需要提取对应的信息,可能还需要处理缺失值和错误的情况。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

莫余

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值