当前位置:网站首页>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()
边栏推荐
- C语言:练习题二
- Mode pont
- D - skiing
- [how to connect the network] Chapter 1: the browser generates messages
- Bigint: handles large numbers (integers of any length)
- Processing random generation line animation
- Reflect the technical depth (unable to speed up)
- Nlp-d60-nlp competition D29
- Prototype
- IDC报告:百度智能云AI Cloud市场份额连续六次第一
猜你喜欢

首批通过!百度智能云曦灵平台获信通院数字人能力评测权威认证

Beifu twincat3 can read and write CSV and txt files

Beifu cx5130 card replacement and transfer of existing authorization files

Beifu PLC model selection -- how to see whether the motor is a multi turn absolute value encoder or a single turn absolute value encoder

Bridge mode

Beifu PLC based on NT_ Shutdown to realize automatic shutdown and restart of controller

解中小企业之困,百度智能云打个样
![[how to connect the network] Chapter 2 (next): receiving a network packet](/img/f5/33e1fd8636fcc80430b3860d069866.png)
[how to connect the network] Chapter 2 (next): receiving a network packet

Electron official docs series: Get Started

Beifu realizes the control of time slice size and quantity through CTU and ton
随机推荐
偶言佳句,孤芳自赏
Processing random generation line animation
What features are added to Photoshop 2022 23.4.1? Do you know anything
Mysql database explanation (III)
Electron official docs series: Best Practices
Custom encapsulation drop-down component
MySQL数据库讲解(三)
[how to connect the network] Chapter 2 (Part 1): establish a connection, transmit data, and disconnect
I - Dollar Dayz
【Spark】. Explanation of several icons of scala file in idea
Arcpy——InsertLayer()函数的使用:掺入图层到地图文档里
tauri vs electron
MySQL explanation (I)
Composite mode
MySQL数据库讲解(六)
Chapter 01_ Installation and use of MySQL under Linux
Electron official docs series: References
Vivado error code [drc pdcn-2721] resolution
HDU 3555 Bomb
C language: Exercise 2