当前位置:网站首页>KITTI Tracking dataset whose format is letf_ top_ right_ bottom to JDE normalied xc_ yc_ w_ h
KITTI Tracking dataset whose format is letf_ top_ right_ bottom to JDE normalied xc_ yc_ w_ h
2022-06-26 13:20:00 【Dabie Mountains】
Transform KITTI tracking to normalized format which is adapt to JDE
- Tracking Than Detection One more level subdirectory , Slightly more complicated
- It is considered here that Van and car It's all regarded as Vehicles
- At the same time, it produced .train Make files , Directly for training
from glob import glob
import numpy as np
import os
class ConvertTxt(object):
def __init__(self):
self.label = r"E:\8_DataSet\KITTI_tracking\label_02" # Original label file
self.label_ids = r"E:\8_DataSet\KITTI_tracking\labels_with_ids" # Target label file directory
self.folder = "0000"
self.file = "0000.txt"
self.label_subdir = None
@staticmethod
def generate_kitti_train():
# Note that the generated here is based on image Benchmarking train file , Include all pictures , And usually after screening lebels_with_ids No way. , Will be less
# Modification is the use of lebels_with_ids Benchmarking , And then txt Use replace Methods to png
path = os.walk(r"E:\8_DataSet\KITTI_tracking\image_02")
for root, directories, files in path:
for _dir in directories:
line = "KITTI/image_02/{}/".format(_dir)
_dir = os.path.join(r"E:\8_DataSet\KITTI_tracking\image_02", _dir)
# dir_list.append(_dir)
txt_list = os.listdir(_dir)
with open("kitti-img.train", 'a') as f:
for item in txt_list:
line1 = line + item
f.writelines(line1)
f.writelines("\n")
''' type--Describes the type of object:'Car', 'Van', 'Truck', 'Pedestrian', 'Pedestrian', 'Person_sitting', 'Cyclist', 'Tram', 'Misc', 'DontCare' bbox: bbox 2D bounding box of object in the image (0-based index): contains `left, top, right, bottom` pixel coordinate '''
def convert_label_with_id(self):
label_txt = os.path.join(self.label, self.file)
self.label_subdir = os.path.join(self.label_ids, self.folder)
frame_array = []
save_lines = []
if not os.path.exists(self.label_subdir):
os.mkdir(self.label_subdir)
with open(label_txt) as f:
lines = f.readlines()
for line in lines:
temp_list = line.strip("\n").split(" ")
_frame, _id, _type, l, t, r, b = temp_list[0], temp_list[1], temp_list[2], temp_list[6], temp_list[7], \
temp_list[8], temp_list[9]
if _type == 'Car' or _type == 'Van':
frame_array.append(_frame)
# TODO Whether or not to id The assignment is -1
xc, yc, w, h = self.lrtb2cxcywh(l, t, r, b)
l, t, r, b = xc, yc, w, h # Regularized coordinates ,yolo Format
# save_line = "{} {} {} {} {} {}".format(0, -1, l, t, r, b)
save_line = "{} {} {} {} {} {}".format(0, _id, l, t, r, b)
save_lines.append(save_line)
return frame_array, save_lines
def write_one_file(self, frame_array, save_lines):
number_list, value_list = self.clasify_frames(frame_array)
line_count = 0
for i in range(len(value_list)):
_th, _hu, _ten, _n = self.transfer_int2txt(value_list[i])
val_txt = "00{}{}{}{}.txt".format(_th, _hu, _ten, _n)
txt_path = os.path.join(self.label_subdir, val_txt)
with open(txt_path, 'w') as f:
for j in range(int(number_list[i])):
f.writelines(str(save_lines[line_count]))
f.writelines("\n")
line_count += 1
def write_files(self):
file_list = []
path = os.walk(self.label)
for root, directories, files in path:
for file in files:
# dir = os.path.join(path,directory)
file_list.append(file)
for file in file_list:
self.file = file
self.folder = file.split(".")[0]
frame_array, save_lines = self.convert_label_with_id()
self.write_one_file(frame_array, save_lines)
def clasify_frames(self, vec):
''' input a sorted list or a array return a list whose element is tuple type, (value, number) '''
length = len(vec)
left = 0
frame_list = []
name_list = []
for i in range(length):
if vec[left] != vec[i]:
frame_num = i - left
frame_list.append(frame_num)
name_list.append(vec[left])
left = i
if i == length - 1:
frame_list.append(i - left + 1)
name_list.append(vec[left])
return frame_list, name_list
@staticmethod
def transfer_int2txt(frme):
frme = int(frme)
if frme == 0:
_n = 0
else:
_n = frme % 10
if frme >= 10:
_ten = int(frme / 10) % 10
else:
_ten = 0
if frme >= 100:
_hu = int(frme / 100) % 10
else:
_hu = 0
if frme >= 1000:
_th = int(frme / 1000) % 10
else:
_th = 0
return _th, _hu, _ten, _n
def lrtb2cxcywh(self, l, t, r, b):
l, t, r, b = float(l), float(t), float(r), float(b)
image_w, image_h = 1242, 375
xc, yc, w, h = self.pascal_voc_to_yolo(l, t, r, b, image_w, image_h)
return xc, yc, w, h
# KITTI tracking 2D The number of high and wide channels of are 375 1242 3
# Convert Pascal_Voc bb to Yolo
# [x_min, y_min, x_max, y_max] ---> [x_center, y_center, width, height]
def pascal_voc_to_yolo(self, x1, y1, x2, y2, image_w, image_h):
return [((x2 + x1) / (2 * image_w)), ((y2 + y1) / (2 * image_h)), (x2 - x1) / image_w, (y2 - y1) / image_h]
covert_test = ConvertTxt()
covert_test.write_files()
边栏推荐
- Es6: iterator
- G - Cow Bowling
- Learning Processing Zoog
- Beifu cx5130 card replacement and transfer of existing authorization files
- Dark horse notes - Common APIs
- Arcpy——InsertLayer()函数的使用:掺入图层到地图文档里
- Beifu PLC realizes data power-off maintenance based on cx5130
- IDC报告:百度智能云AI Cloud市场份额连续六次第一
- Arcpy——InsertLayer()函數的使用:摻入圖層到地圖文檔裏
- 适配器模式(Adapter)
猜你喜欢

Thinking caused by the error < note: candidate expectations 1 argument, 0 provided >

IDC报告:百度智能云AI Cloud市场份额连续六次第一

Enjoy element mode (flyweight)

组合模式(Composite )

Composite mode

桥接模式(Bridge)
![Hdu1724[Simpson formula for integral]ellipse](/img/57/fb5098e150b5f3d91a5d0983a336ee.png)
Hdu1724[Simpson formula for integral]ellipse

MySQL数据库讲解(三)

Word document export (using fixed template)
Summary of wechat applet test points
随机推荐
Nlp-d60-nlp competition D29
Mysql database explanation (III)
Analysis and protection of heart blood dripping vulnerability (cve-2014-0160)
Common faults of MySQL database - forgetting database password
POJ 3070 Fibonacci
Custom encapsulation drop-down component
Uva5009 error curves three points
Electron official docs series: Development
Processing function translate (mousex, mousey) learning
UVA5009 Error Curves三分
HDU 5860
Dark horse notes - Common APIs
Chapter 01_ Installation and use of MySQL under Linux
code force Party Lemonade
MySQL explanation (I)
ES6 module
Electron official docs series: Examples
MariaDB study notes
HDU1724[辛普森公式求积分]Ellipse
F - Charm Bracelet