提取visdrone2019数据集数据_第1页
提取visdrone2019数据集数据_第2页
提取visdrone2019数据集数据_第3页
提取visdrone2019数据集数据_第4页
提取visdrone2019数据集数据_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、visdrone2019数据集数据这通过只提取类跟踪数据集,因此对其更改,如果需要提取多类的直接打开即可,同时呢这个转换为多累跟踪数据集,其中数据的格式为:,其中的类别为: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)# import shutil# -110 类是我们需要检测和跟踪的标# van# truck# tricycle# awning-tricy

2、cle (8), - 7# bus# motor# -# others(11)# We need 10 classes to detect and trackingvan: 4,:param img: opencv(numpy array): HWC:param boxes: a list of boxes: left(box0), top(box1), width(box2), height(box3)box = list(map(lambda x: int(x + 0.5), box) # 四舍五imgbox1: box1 + box3, box0: box0 + box2 = 0, 0,

3、 0return imgdef gen_dot_train_file(data_root, rel_path, out_root, f_name=detrac.train):param rel_path:param out_root:param f_name:return:if not (os.path.isdir(data_root) and os.path.isdir(out_root):out_f_path = out_root + / + f_namecnt = 0with open(out_f_path, w) as f:root = data_root + rel_pathseqs

4、 = x for x in os.listdir(root)seqs.sort()# seqs = sorted(seqs, key=lambda x: int(x.split(_)-1)for seq in tqdm(seqs):img_dir = root + / + seq # + /img1img_list = x for x in os.listdir(img_dir)img_list.sort()for img in img_list:if img.endswith(.jpg):f.write(item + n)cnt += 1print(Total :d images for t

5、raining.format(cnt)def gen_track_dataset(src_root, dst_root, viz_root=None):dst_img_root = dst_root + /imagesdst_txt_root = dst_root + /labels_with_idsif not os.path.isdir(dst_img_root):os.makedirs(dst_img_root)# id, 0# track_start_id = 0track_start_id_dict = defaultdict(int) # start id0开始for cls_id

6、 in id2cls.keys():# 遍历每个视频序列for seq in tqdm(seq_names):print(Processing :.format(seq)seq_img_dir = src_root + /sequences/ + seqseq_txt_f_path = src_root + /annotations/ + seq + .txt# ()dst_seq_img_dir = dst_img_root + / + seqif not os.path.isdir(dst_seq_img_dir):os.makedirs(dst_seq_img_dir)dst_seq_t

7、xt_dir = dst_txt_root + / + seqif not os.path.isdir(dst_seq_txt_dir):os.makedirs(dst_seq_txt_dir)# seqtrack_id# seq_max_tar_id = 0seq_max_tra_id_dictk = 0# 视频序列seq_frame_names = os.listdir(seq_img_dir)seq_frame_names.sort()label_n_lines = len(label_lines)for line_i, line in enumerate(label_lines):li

8、ne = int(x) for x in line.strip().split(,)seq_label_arrayline_i = lineseq_label_arrayline_i = line# 这需要注意的是,数据集的格式为:# ,# 数据集的类别为:# 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)# 0boxbox,因此分两部分处理,把忽略的和真

9、正的类别进区分处理# , seq_objs_label_dict = defaultdict(list)# seqdictclasstarget idseq_cls_target_ids_dict = defaultdict(list)tmp_ids_dict = defaultdict(set)cls_id = label7 - 1target_id = label1#for cls_id in tmp_ids_dict.keys():track_ids = tmp_ids_dictcls_id# track_ids = set(track_ids)track_ids = list(trac

10、k_ids)track_ids.sort()seq_cls_target_ids_dictcls_id = track_ids# track_ids = tmp_ids_dict9# track_ids = list(track_ids)# track_ids.sort()for k, v in seq_cls_target_ids_dict.items():seq_max_tra_id_dictk = len(v)# print( max track id: :d, start id: :d#.format(id2cls9, seq_max_tra_id_dict0, track_start

11、_id_dict0)for k in id2cls.keys():# 读取每帧for fr_id in seq_objs_label_dict.keys():# -fr_labels = seq_objs_label_dictfr_idprint(Err: empty image.)continueviz_path = viz_dir + / + fr_name# img数据作为可视化输出img_viz = copy.deepcopy(img)# - label(txt)# label_str(or)fr_label_strs = for label in fr_labels:# cls_id

12、 and cls_nameobj_type = label7assert 0 obj_type 11cls_id = obj_type - 1 # 0开始# cls_name = id2clscls_idtarget_id = label1score = label6truncation = label8 # no truncation = 0 (truncation ratio 0%), and partial truncation = 1 (truncation ratio 1% 50%)occlusion = label9# - label(label/): 在归化之前if not (v

13、iz_root is None): # 如果可视化录不为空# targetbboxcv2.rectangle(img_viz,pt_1,pt_2,cls_str = id2clscls_idveh_type_str_size = cv2.getTextSize(cls_str,cv2.FONT_HERSHEY_PLAIN,1.3,1)0(pt_10,cv2.FONT_HERSHEY_PLAIN,1.3,225, 255, 255,1)tr_id_str_size = cv2.getTextSize(tr_id_str,cv2.FONT_HERSHEY_PLAIN,1.3,1)0cv2.putT

14、ext(img_viz,tr_id_str,(pt_10,pt_11 + veh_type_str_size1 + tr_id_str_size1 + 8),cv2.FONT_HERSHEY_PLAIN,1.3,225, 255, 255,1)# bbox中点坐标bbox_center_x = bbox_left + bbox_width * 0.5bbox_center_y = bbox_top + bbox_height * 0.5# bbox(0.0, 1.0)bbox_center_x /= Wbbox_center_y /= Hbbox_width /= Wbbox_height /

15、= H# label, label成完成才输出# class_id, track_id, bbox_center_x, box_center_y, bbox_width, bbox_height# label_str = :d :d :.6f :.6f :.6f :.6fn.format(cls_id,track_id,bbox_center_x,bbox_center_y,bbox_width,bbox_height)label_str = :d :d :.6f :.6f :.6f :.6fn.format(0,track_id,bbox_center_x,bbox_center_y,bbo

16、x_width,bbox_height)fr_label_strs.append(label_str)# seq, track_start_idfor cls_id in id2cls.keys():print(Total :d frames.format(frame_cnt)viz_root=E:/MOTdata/VisDrone2020/viz_result_val)转换完成以后,进成.train件:88 . 88(| -_- |)0 = /0_/-_. | |/ ./ | : |/ / _| -:- |- | | - / | |佛祖保佑Version: 1.0FilePath: srcg

17、en_data_path copy.pyLastEditTime: 2021-05-28 15:23:35import globprint(image22:, file=f)f.close()def gen_dot_train_file(data_root, rel_path, out_root, f_name=VisDrone2019.train):To generate the dot train file:param data_root:param rel_path:param out_root:param f_name:return:if not (os.path.isdir(data

18、_root) and os.path.isdir(out_root):out_f_path = out_root + / + f_namecnt = 0with open(out_f_path, w) as f:root = data_root +/+ rel_pathseqs = x for x in os.listdir(root)seqs.sort()# seqs = sorted(seqs, key=lambda x: int(x.split(_)-1)for seq in tqdm(seqs):img_dir = root + / + seq # + /img1img_list = x for x in os.listdir(img_dir)img_list.sort()print(Total :d images for training.format(cnt)def clean_train_set(im

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论