文章目录
- UAVDT数据集转化为MOT数据集
- MOT17 数据集格式
- train
- det.txt
- gt.txt
- seqinfo.ini
- test
- det.txt
- UAVDT
- 1. 自行创建下面文件夹路径
- 2. 操作并得到gt.txt
- seqinfo.ini
- 代码
UAVDT数据集转化为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相同。
UAVDT
其中,gt.txt 与 det.txt 中标签的含义在 readme.txt 中已经详细给出,现需要进行MOT17对应的格式。
1. 自行创建下面文件夹路径
├── UAVDT-MOT
│ ├── images
│ │ ├──train
│ │ │ ├──XXX(视频的文件夹名称)
│ │ │ │ ├──det
│ │ │ │ │ ├──det.txt(目标跟踪不需要)
│ │ │ │ ├──gt
│ │ │ │ │ ├──gt.txt
│ │ │ │ ├──img1
│ │ │ │ │ ├──XXX(jpg文件,其中名称与txt文件名称对应)
│ │ │ │ ├──seqinfo.ini
│ │ ├──test
│ │ │ ├──XXX(视频的文件夹名称)
│ │ │ │ ├──det
│ │ │ │ │ ├──det.txt(目标跟踪不需要)
│ │ │ │ ├──img1
│ │ │ │ │ ├──XXX(jpg文件,其中名称与txt文件名称对应)
│ │ │ │ ├──seqinfo.ini
│ ├── labels_with_ids
│ │ ├──train
│ │ │ ├──XXX(视频的文件夹名称)
│ │ │ │ ├──image1
│ │ │ │ │ ├──XXX(txt文件,其中名称与jpg文件名称对应)
目前UAVDT的文件路径如下,
├── UAVDT
│ ├── UAV-benchmark-M
│ │ ├── XXX(视频的文件夹名称)
│ │ │ ├──XXX(jpg文件,其中名称与txt文件名称对应)
│ ├── UAV-benchmark-MOTD_v1.0
│ │ ├──GT
│ │ │ ├──XXX_gt.txt
│ │ │ ├──XXX_gt_ignore.txt
│ │ │ ├──XXX_gt_whole.txt
需要进行的工作:
jpg文件已有,
- gt.txt
- seqinfo.ini
- txt文件(无法获得)
2. 操作并得到gt.txt
gt.txt
的前7个标签是 *_gt.txt
的前7个标签;
gt.txt
的第8个标签是 *_gt_whole.txt
的第9个标签;
gt.txt
的前9个标签是 *_gt_whole.txt
的第7和第8个标签决定,共有12种情况;对应关系如下:
out-of-view | occlusion | visibility ratio |
---|---|---|
1 | 1 | 1 |
1 | 2 | 0.8 |
1 | 3 | 0.85 |
1 | 4 | 0.95 |
2 | 1 | 0.85 |
2 | 2 | 0.5 |
2 | 3 | 0.6 |
2 | 4 | 0.7 |
3 | 1 | 0.85 |
3 | 2 | 0.6 |
3 | 3 | 065 |
3 | 4 | 0.75 |
seqinfo.ini
代码
import os
from tqdm import tqdm
import shutil
def del_filefolder(path):
list = ['M0403', 'M1301', 'M0203', 'M0701', 'M0209', 'M0208', 'M1009', 'M0802', 'M0602', 'M1001', 'M1401', 'M0606',
'M1101', 'M1302', 'M1303', 'M1007', 'M1004', 'M0205', 'M0801', 'M0601']
for i in list:
folder_path=os.path.join(path,'UAV-benchmark-M',i)
print(folder_path)
if os.path.exists(folder_path):
shutil.rmtree(folder_path)
print('del folder over!')
def del_file(path):
list = ['M0403', 'M1301', 'M0203', 'M0701', 'M0209', 'M0208', 'M1009', 'M0802', 'M0602', 'M1001', 'M1401', 'M0606',
'M1101', 'M1302', 'M1303', 'M1007', 'M1004', 'M0205', 'M0801', 'M0601']
for i in list:
gt_txt_path=os.path.join(path,'GT',str(i)+'_gt.txt')
gt_whole_txt_path=os.path.join(path,'GT',str(i)+'_gt_whole.txt')
if os.path.exists(gt_txt_path):
os.remove(gt_txt_path)
print('del gt_file over!')
if os.path.exists(gt_whole_txt_path):
os.remove(gt_whole_txt_path)
print('del gt_whole_file over!')
def count(path):
'''
:param path: "1.txt"
:return:
'''
vedio_path = os.path.join(path, "UAV-benchmark-M")
vedio_set = os.listdir(vedio_path)
print(vedio_set)
gt_path = os.path.join(path, 'GT')
print(gt_path)
# file_path=os.path.join(path,'sequences')
# file_set=os.listdir(file_path)
# # print(file_set)
for i in tqdm(vedio_set):
txt_path=os.path.join(gt_path,str(i)+'_gt.txt')
whole_txt_path=os.path.join(gt_path,str(i)+'_gt_whole.txt')
txt_count = len(open(txt_path,'rU').readlines())
whole_txt_count = len(open(whole_txt_path,'rU').readlines())
print('txt_count:',txt_count)
print('whole_txt_count:',whole_txt_count)
if(txt_count==whole_txt_count):
print('ok')
else:
print(str(i)+'XXXXXXXXXXXXXX')
print('----------------------------------------------')
if __name__ == '__main__':
del_filefolder('/home/course/ldw/dataset/UAVDT_MOT/')
del_file('/home/course/ldw/dataset/UAVDT_MOT/')
# count('/home/course/ldw/dataset/UAVDT_MOT/')
import os
import shutil
import time
from tqdm import tqdm
from PIL import Image
def process(path):
vedio_path = os.path.join(path, "UAV-benchmark-M")
vedio_set = os.listdir(vedio_path)
print(vedio_set)
gt_path = os.path.join(path, 'GT')
print(gt_path)
# file_path=os.path.join(path,'sequences')
# file_set=os.listdir(file_path)
# # print(file_set)
for i in tqdm(vedio_set):
file_path = os.path.join(path, 'train', str(i))
makedir(file_path)
file_gt_path = os.path.join(file_path, 'gt')
makedir(file_gt_path)
gt_url = file_gt_path + '\\gt.txt'
print(gt_url) # E:\Projects\pythonprojects\Test\uavdt2mot\train\M0101\gt\gt.txt
if not os.path.isfile(gt_url):
fd = open(gt_url, mode="w", encoding="utf-8")
file = open(gt_url, 'w').close()
gt1_url = file_gt_path + '\\gt1.txt'
print(gt1_url) # E:\Projects\pythonprojects\Test\uavdt2mot\train\M0101\gt\gt.txt
if not os.path.isfile(gt1_url):
fd = open(gt1_url, mode="w", encoding="utf-8")
file = open(gt1_url, 'w').close()
gt2_url = file_gt_path + '\\gt2.txt'
print(gt2_url) # E:\Projects\pythonprojects\Test\uavdt2mot\train\M0101\gt\gt.txt
if not os.path.isfile(gt2_url):
fd = open(gt2_url, mode="w", encoding="utf-8")
file = open(gt2_url, 'w').close()
gt_txt_name = os.path.join(gt_path, i + '_gt.txt')
print(gt_txt_name)
gt_whole_name = os.path.join(gt_path, i + '_gt_whole.txt')
print(gt_whole_name)
f_gt = open(gt_txt_name, "r")
f_whole_gt = open(gt_whole_name, 'r')
for line2 in f_whole_gt.readlines():
line2 = line2.replace("\n", "")
if line2.endswith(","): # filter data
line2 = line2.rstrip(",")
line_list2 = [int(i) for i in line2.split(",")]
if (line_list2[6] == 1 and line_list2[7] == 1):
line_list2[7] = 1
if (line_list2[6] == 1 and line_list2[7] == 2):
line_list2[7] = 0.8
if (line_list2[6] == 1 and line_list2[7] == 3):
line_list2[7] = 0.85
if (line_list2[6] == 1 and line_list2[7] == 4):
line_list2[7] = 0.95
if (line_list2[6] == 2 and line_list2[7] == 1):
line_list2[7] = 0.85
if (line_list2[6] == 2 and line_list2[7] == 2):
line_list2[7] = 0.5
if (line_list2[6] == 2 and line_list2[7] == 3):
line_list2[7] = 0.6
if (line_list2[6] == 2 and line_list2[7] == 4):
line_list2[7] = 0.7
if (line_list2[6] == 3 and line_list2[7] == 1):
line_list2[7] = 0.85
if (line_list2[6] == 3 and line_list2[7] == 2):
line_list2[7] = 0.6
if (line_list2[6] == 3 and line_list2[7] == 3):
line_list2[7] = 0.65
if (line_list2[6] == 3 and line_list2[7] == 4):
line_list2[7] = 0.75
str_text2 = ',' + str(line_list2[8]) + ',' + str(line_list2[7])
print(str_text2)
with open(gt1_url, 'a') as file_name:
file_name.write(str_text2 + '\n')
for line in f_gt.readlines():
line = line.replace("\n", "")
if line.endswith(","): # filter data
line = line.rstrip(",")
line_list = [int(i) for i in line.split(",")]
# print(line_list)
str_text = str(line_list[0]) + ',' + str(line_list[1]) + ',' + str(line_list[2]) + ',' + str(
line_list[3]) + ',' + str(line_list[4]) + ',' + str(line_list[5]) + ',' + str(
line_list[6])
print(str_text)
with open(gt2_url, 'a') as file_name:
file_name.write(str_text + '\n')
com(gt1_url,gt2_url,gt_url)
def del_file(path):
if os.path.exists(path):
os.remove(path)
print('del over!')
def move(old_path, new_path):
makedir(new_path)
copyfile(old_path, new_path)
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 com(file1path,file2path,file_path):
file_1 = open(file1path, 'r', encoding='utf-8')
file_2 = open(file2path, 'r', encoding='utf-8')
list1 = []
for line in file_1.readlines():
ss = line.strip()
list1.append(ss)
file_1.close()
list2 = []
for line in file_2.readlines():
ss = line.strip()
list2.append(ss)
file_2.close()
file_new = open(file_path, 'w', encoding='utf-8')
for i in range(len(list1)):
# 将两个txt文件合并到一行 中间用分隔符隔开
sline = list2[i] + list1[i]
# 写入新的txt文件 换行
file_new.write(sline + '\n')
file_new.close()
if __name__ == '__main__':
path = r'E:\Projects\pythonprojects\Test\uavdt2mot'
process(path)
from main1_win import *
def process(path):
vedio_path = os.path.join(path, "UAV-benchmark-M")
vedio_set = os.listdir(vedio_path)
print(vedio_set)
gt_path = os.path.join(path, 'GT')
print(gt_path)
# file_path=os.path.join(path,'sequences')
# file_set=os.listdir(file_path)
# # print(file_set)
for i in tqdm(vedio_set):
file_path = os.path.join(path, 'train', str(i))
print('file_path:',file_path)
makedir(file_path)
file_gt_path = os.path.join(file_path, 'gt')
makedir(file_gt_path)
gt_url = file_gt_path + '\\gt.txt'
print(gt_url) # E:\Projects\pythonprojects\Test\uavdt2mot\train\M0101\gt\gt.txt
gt1_url = file_gt_path + '\\gt1.txt'
print(gt1_url) # E:\Projects\pythonprojects\Test\uavdt2mot\train\M0101\gt\gt.txt
gt2_url = file_gt_path + '\\gt2.txt'
print(gt2_url)
# del_file(gt1_url)
# del_file(gt2_url)
print('***********************************')
img_path = os.path.join(vedio_path,str(i))
img_set = os.listdir(img_path)
img = Image.open(os.path.join(img_path, img_set[0]))
ini_path = file_path
print(ini_path)
ini_file = ini_path + '\\seqinfo.ini'
print(ini_file)
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=' + i + '\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')
if __name__ == '__main__':
path = r'E:\Projects\pythonprojects\Test\uavdt2mot'
process(path)