工作情况:
kitti数据集的标签(转换成FairMOT类似的gt)
以下是处理图片和gt文本的程序操作,仅做个人记录!!!
1.将原先kitti tracking数据集的标签 修改 去掉type用文本来表示 改成数字代表 同时将空格改成逗号
效果图
kitti tracking 标签含义:
The label files contain the following information, which can be read and
written using the matlab tools (readLabels.m) provided within this devkit.
All values (numerical or strings) are separated via spaces, each row
corresponds to one object. The 17 columns represent:
#Values Name Description
----------------------------------------------------------------------------
1 frame Frame within the sequence where the object appearers
1 track id Unique tracking id of this object within this sequence
1 type Describes the type of object: 'Car', 'Van', 'Truck',
'Pedestrian', 'Person_sitting', 'Cyclist', 'Tram',
'Misc' or 'DontCare'
1 truncated Integer (0,1,2) indicating the level of truncation.
Note that this is in contrast to the object detection
benchmark where truncation is a float in [0,1].
1 occluded Integer (0,1,2,3) indicating occlusion state:
0 = fully visible, 1 = partly occluded
2 = largely occluded, 3 = unknown
1 alpha Observation angle of object, ranging [-pi..pi]
4 bbox 2D bounding box of object in the image (0-based index):
contains left, top, right, bottom pixel coordinates
3 dimensions 3D object dimensions: height, width, length (in meters)
3 location 3D object location x,y,z in camera coordinates (in meters)
1 rotation_y Rotation ry around Y-axis in camera coordinates [-pi..pi]
1 score Only for results: Float, indicating confidence in
detection, needed for p/r curves, higher is better.
附 转换代码:
import os
import numpy as np
import pandas as pd
import os.path as osp
def replace(file, old_content, new_content):
content = read_file(file)
content = content.replace(old_content, new_content)
rewrite_file(file, content)
# 读文件内容
def read_file(file):
with open(file, encoding='UTF-8') as f:
read_all = f.read()
f.close()
return read_all
# 写内容到文件
def rewrite_file(file, data):
with open(file, 'w', encoding='UTF-8') as f:
f.write(data)
f.close()
src_data='/media/ckq/data/kitti/MOT/images/train'
seqs = [s for s in os.listdir(src_data)]
#print(seqs)
for seq in seqs:
path=osp.join(src_data,seq,'gt/gt.txt')
# seq_gt_path = osp.join(src_data, seq, 'gt/gt.txt')
# print(seq_gt_path)
# gt = np.loadtxt(seq_gt_path, dtype=np.str, delimiter=',') # 加载成np格式
# print(str(gt))
replace(path, ' ', ',')
replace(path, 'DontCare', '10')
replace(path, 'Person', '1')
replace(path, 'Pedestrian', '2')
replace(path, 'Car', '3')
replace(path, 'Person_sitting', '4')
replace(path, 'Cyclist', '5')
replace(path, 'Van', '6')
replace(path, 'Truck', '7')
replace(path, 'Tram', '8')
replace(path, 'Misc', '9')
2.之后开始给每个数据及的每张图片进行标签: 首先说一下 我的需求是标注Car: kitti数据集标签生成 gen_lables_kitti_car.py:
附代码(对照FairMOT 和`FairVehicle的生成标签代码写):
import os.path as osp
import os
import shutil
import numpy as np
def mkdirs(d):
# if not osp.exists(d):
if not osp.isdir(d):
os.makedirs(d)
data_root = '/media/ckq/data/kitti/'
seq_root = data_root + 'MOT/images/train'
label_root = data_root + 'MOT/labels_with_ids/train'
if not os.path