def _construct_sequence(self, sequence_name): sequence_path = sequence_name nz = 8 ext = 'jpg' start_frame = 1 anno_path = '{}/{}/annotation/groundtruth.txt'.format( self.base_path, sequence_name) try: ground_truth_rect = np.loadtxt(str(anno_path), dtype=np.float64) except: ground_truth_rect = np.loadtxt(str(anno_path), delimiter=',', dtype=np.float64) end_frame = ground_truth_rect.shape[0] frames = [ '{base_path}/{sequence_path}/img/{frame:0{nz}}.{ext}'.format( base_path=self.base_path, sequence_path=sequence_path, frame=frame_num, nz=nz, ext=ext) for frame_num in range(start_frame, end_frame + 1) ] return Sequence(sequence_name, frames, ground_truth_rect)
def _construct_sequence(self, sequence_info): sequence_path = sequence_info['path'] nz = sequence_info['nz'] ext = sequence_info['ext'] start_frame = sequence_info['startFrame'] end_frame = sequence_info['endFrame'] init_omit = 0 if 'initOmit' in sequence_info: init_omit = sequence_info['initOmit'] frames = [ '{base_path}/{sequence_path}/{frame:0{nz}}.{ext}'.format( base_path=self.base_path, sequence_path=sequence_path, frame=frame_num, nz=nz, ext=ext) for frame_num in range(start_frame + init_omit, end_frame + 1) ] anno_path = '{}/{}'.format(self.base_path, sequence_info['anno_path']) # NOTE: OTB has some weird annos which panda cannot handle ground_truth_rect = load_text(str(anno_path), delimiter=(',', None), dtype=np.float64, backend='numpy') return Sequence(sequence_info['name'], frames, 'otb', ground_truth_rect[init_omit:, :], object_class=sequence_info['object_class'])
def _construct_sequence(self, sequence_name): class_name = sequence_name.split('-')[0] anno_path = '{}/{}/{}/groundtruth.txt'.format(self.base_path, class_name, sequence_name) try: ground_truth_rect = np.loadtxt(str(anno_path), dtype=np.float64) except: ground_truth_rect = np.loadtxt(str(anno_path), delimiter=',', dtype=np.float64) frames_path = '{}/{}/{}/img'.format(self.base_path, class_name, sequence_name) frame_list = [ frame for frame in os.listdir(frames_path) if frame.endswith(".jpg") ] frame_list.sort(key=lambda f: int(f[:-4])) frames_list = [ os.path.join(frames_path, frame) for frame in frame_list ] return Sequence(sequence_name, frames_list, ground_truth_rect.reshape(-1, 4))
def _construct_sequence(self, set, sequence_name): # anno_path = '{}/{}/anno/{}.txt'.format(self.base_path, set, sequence_name) # Below line fixes error produced by line 35 :D anno_path = os.path.join(os.getcwd(), set) + '/anno/' + sequence_name + '.txt' ground_truth_rect = load_text(str(anno_path), delimiter=',', dtype=np.float64, backend='numpy') # frames_path = '{}/{}/frames/{}'.format(self.base_path, set, sequence_name) # Below line fixes error produced by line 39 :D frames_path = os.path.join(os.getcwd(), set) + '/zips/' + sequence_name frame_list = [ frame for frame in os.listdir(frames_path) if frame.endswith(".jpg") ] frame_list.sort(key=lambda f: int(f[:-4])) frames_list = [ os.path.join(frames_path, frame) for frame in frame_list ] return Sequence(sequence_name, frames_list, 'trackingnet', ground_truth_rect.reshape(-1, 4))
def _construct_sequence(self, sequence_name): sequence_path = sequence_name nz = 8 ext = 'jpg' start_frame = 1 anno_path = '{}/{}/groundtruth.txt'.format(self.base_path, sequence_name) try: ground_truth_rect = np.loadtxt(str(anno_path), dtype=np.float64) except: ground_truth_rect = np.loadtxt(str(anno_path), delimiter=',', dtype=np.float64) end_frame = ground_truth_rect.shape[0] frames = ['{base_path}/{sequence_path}/color/{frame:0{nz}}.{ext}'.format(base_path=self.base_path, sequence_path=sequence_path, frame=frame_num, nz=nz, ext=ext) for frame_num in range(start_frame, end_frame+1)] # Convert gt if ground_truth_rect.shape[1] > 4: gt_x_all = ground_truth_rect[:, [0, 2, 4, 6]] gt_y_all = ground_truth_rect[:, [1, 3, 5, 7]] x1 = np.amin(gt_x_all, 1).reshape(-1,1) y1 = np.amin(gt_y_all, 1).reshape(-1,1) x2 = np.amax(gt_x_all, 1).reshape(-1,1) y2 = np.amax(gt_y_all, 1).reshape(-1,1) ground_truth_rect = np.concatenate((x1, y1, x2-x1, y2-y1), 1) return Sequence(sequence_name, frames, 'vot', ground_truth_rect)
def _construct_sequence(self, sequence_info): sequence_path = sequence_info['path'] nz = sequence_info['nz'] ext = sequence_info['ext'] start_frame = sequence_info['startFrame'] end_frame = sequence_info['endFrame'] init_omit = 0 if 'initOmit' in sequence_info: init_omit = sequence_info['initOmit'] frames = [ '{base_path}/{sequence_path}/{frame:0{nz}}.{ext}'.format( base_path=self.base_path, sequence_path=sequence_path, frame=frame_num, nz=nz, ext=ext) for frame_num in range(start_frame + init_omit, end_frame + 1) ] anno_path = '{}/{}'.format(self.base_path, sequence_info['anno_path']) try: ground_truth_rect = np.loadtxt(str(anno_path), dtype=np.float64) except: ground_truth_rect = np.loadtxt(str(anno_path), delimiter=',', dtype=np.float64) return Sequence(sequence_info['name'], frames, ground_truth_rect[init_omit:, :])
def _construct_sequence(self, sequence_name): sequence_path = sequence_name anno_path = '{}/{}/{}.txt'.format(self.base_path, sequence_name, 'groundtruth') #print(anno_path) if os.path.exists(str(anno_path)): try: ground_truth_rect = np.loadtxt(str(anno_path), dtype=np.float64) except: ground_truth_rect = np.loadtxt(str(anno_path), delimiter=',', dtype=np.float64) end_frame = ground_truth_rect.shape[0] ground_truth_rect = ground_truth_rect[:, [0, 1, 2, 3]] else: #print('ptbdataset, no full groundtruth file, use init file') anno_path = '{}/{}/init.txt'.format(self.base_path, sequence_name) try: ground_truth_rect = np.loadtxt(str(anno_path), dtype=np.float64) except: ground_truth_rect = np.loadtxt(str(anno_path), delimiter=',', dtype=np.float64) #print(ground_truth_rect.shape) ground_truth_rect = ground_truth_rect.reshape(1, 4) frames_path = '{}/{}/color'.format(self.base_path, sequence_path) rgb_frame_list = [ frame for frame in os.listdir(frames_path) if frame.endswith('jpg') ] rgb_frame_list.sort(key=lambda f: int(f[0:8])) rgb_frame_list = [ os.path.join(frames_path, frame) for frame in rgb_frame_list ] #print('votddataset, rgb_frame_list[0] %s' % rgb_frame_list[0]) depth_frames_path = '{}/{}/depth'.format(self.base_path, sequence_path) depth_frame_list = [ frame for frame in os.listdir(depth_frames_path) if frame.endswith('png') ] depth_frame_list.sort(key=lambda f: int(f[0:8])) depth_frame_list = [ os.path.join(depth_frames_path, frame) for frame in depth_frame_list ] if len(ground_truth_rect) == 0: ground_truth_rect = np.zeros((len(rgb_frame_list), 4)) return Sequence(sequence_name, rgb_frame_list, ground_truth_rect, depth_frame_list)
def _construct_sequence(self, sequence_info): #count number of images totalFiles = 0 totalDir = 0 for base, dirs, files in os.walk("/gdrive/My Drive/images"): for directories in dirs: totalDir += 1 for Files in files: totalFiles += 1 print("Total Files: " + str(totalFiles)) sequence_path = sequence_info['path'] nz = sequence_info['nz'] ext = sequence_info['ext'] start_frame = 1 end_frame = totalFiles - 1 init_omit = 0 frames = [ '{base_path}/{sequence_path}/{frame:0{nz}}.{ext}'.format( base_path=self.base_path, sequence_path=sequence_path, frame=frame_num, nz=nz, ext=ext) for frame_num in range(start_frame + init_omit, end_frame + 1) ] #load inital BB gt = OrderedDict() #define numbers of tracked objects with open('/gdrive/My Drive/data/data.txt') as myfile: total_lines = sum(1 for line in myfile) print("detected Objects:" + str(total_lines)) #define ground truth data for first frame with open('/gdrive/My Drive/data/data.txt') as myfile: for i in range(0, total_lines): line = myfile.readline() data = (line.strip().split(" ")) data = [int(x) for x in data] gt.update({int(i): data}) print(gt) objIDs = list() for i in range(0, total_lines): objIDs.append(int(i)) return Sequence(sequence_info['name'], frames, 'otb', ground_truth_rect=gt, object_class=sequence_info['object_class'], multiobj_mode=True, object_ids=objIDs)
def _construct_sequence(self, sequence_name): sequence_path = sequence_name nz = 8 start_frame = 1 if self.dtype == 'color': ext = 'jpg' elif self.dtype in ['R', 'G', 'B', 'RColormap', 'GColormap', 'BColormap']: ext = 'jpg' elif self.dtype == 'rgbd': ext = ['jpg', 'png'] # Song not implemented yet else: ext = 'png' anno_path = '{}/{}/groundtruth.txt'.format(self.base_path, sequence_name) try: ground_truth_rect = np.loadtxt(str(anno_path), dtype=np.float64) except: ground_truth_rect = np.loadtxt(str(anno_path), delimiter=',', dtype=np.float64) end_frame = ground_truth_rect.shape[0] if self.dtype in ['sigmoid', 'sigmoid_depth', 'colormap_depth', 'colormap', 'normalized_depth', 'raw_depth', 'centered_colormap', 'centered_normalized_depth', 'centered_raw_depth']: group = 'depth' elif self.dtype in ['color', 'R', 'G', 'B', 'RColormap', 'GColormap', 'BColormap']: group = 'color' else: group = self.dtype if self.dtype in ['rgbd', 'rgbcolormap']: frames = [{'color': '{base_path}/{sequence_path}/color/{frame:0{nz}}.jpg'.format(base_path=self.base_path,sequence_path=sequence_path, frame=frame_num, nz=nz), 'depth': '{base_path}/{sequence_path}/depth/{frame:0{nz}}.png'.format(base_path=self.base_path,sequence_path=sequence_path, frame=frame_num, nz=nz) }for frame_num in range(start_frame, end_frame+1)] # color_frames = ['{base_path}/{sequence_path}/color/{frame:0{nz}}.jpg'.format(base_path=self.base_path, # sequence_path=sequence_path, frame=frame_num, nz=nz) # for frame_num in range(start_frame, end_frame+1)] # frames = {'color': color_frames, 'depth': depth_frames} else: frames = ['{base_path}/{sequence_path}/{group}/{frame:0{nz}}.{ext}'.format(base_path=self.base_path, sequence_path=sequence_path, group=group, frame=frame_num, nz=nz, ext=ext) for frame_num in range(start_frame, end_frame+1)] # Convert gt if ground_truth_rect.shape[1] > 4: gt_x_all = ground_truth_rect[:, [0, 2, 4, 6]] gt_y_all = ground_truth_rect[:, [1, 3, 5, 7]] x1 = np.amin(gt_x_all, 1).reshape(-1,1) y1 = np.amin(gt_y_all, 1).reshape(-1,1) x2 = np.amax(gt_x_all, 1).reshape(-1,1) y2 = np.amax(gt_y_all, 1).reshape(-1,1) ground_truth_rect = np.concatenate((x1, y1, x2-x1, y2-y1), 1) return Sequence(sequence_name, frames, 'cdtb', ground_truth_rect, dtype=self.dtype)
def _construct_sequence(self, sequence_name): index = self.seq_names.index(sequence_name) img_files = sorted(glob.glob(self.seq_dirs[index] + '/*.jpg')) if len(img_files) == 0: img_files = sorted(glob.glob(self.seq_dirs[index] + '.png')) with open(self.anno_files[index], 'r') as f: anno = np.loadtxt(f, delimiter=',', skiprows=1, dtype=int) anno = anno[:, 1:] assert anno.shape[1] == 4 return Sequence(sequence_name, img_files, anno.reshape(-1, 4))
def _construct_sequence(self, sequence_info): sequence_path = sequence_info['path'] nz = sequence_info['nz'] ext = sequence_info['ext'] start_frame = sequence_info['startFrame'] end_frame = sequence_info['endFrame'] init_omit = 0 if 'initOmit' in sequence_info: init_omit = sequence_info['initOmit'] if isinstance(ext, list): for e in ext: first_frame_path = '{base_path}/{sequence_path}/{frame:0{nz}}.{ext}'.format( base_path=self.base_path, sequence_path=sequence_path, frame=start_frame + init_omit, nz=nz, ext=e) if os.path.isfile(first_frame_path): ext = e break if isinstance(ext, list): raise Exception('Sequence {} not found'.format( sequence_info['name'])) frames = [ '{base_path}/{sequence_path}/{frame:0{nz}}.{ext}'.format( base_path=self.base_path, sequence_path=sequence_path, frame=frame_num, nz=nz, ext=ext) for frame_num in range(start_frame + init_omit, end_frame + 1) ] # frames = ['{base_path}/{sequence_path}/{frame:0{nz}}.{ext}'.format(base_path=self.base_path, # sequence_path=sequence_path, frame=frame_num, # nz=nz, ext=ext) for frame_num in # range(1, end_frame + 1)] anno_path = '{}/{}'.format(self.base_path, sequence_info['anno_path']) #print("anno_path: {}".format(anno_path)) try: ground_truth_rect = np.loadtxt(str(anno_path), dtype=np.float64) except: ground_truth_rect = np.loadtxt(str(anno_path), delimiter=',', dtype=np.float64) return Sequence(sequence_info['name'], frames, ground_truth_rect[init_omit:, :])
def _construct_sequence(self, sequence_name): sequence_path = sequence_name #nz = 8 ext = 'png' start_frame = 1 anno_path = '{}/processed/{}/{}.txt'.format(self.base_path, sequence_name, 'groundtruth') print(anno_path) if os.path.exists(str(anno_path)): try: ground_truth_rect = np.loadtxt(str(anno_path), dtype=np.float64) except: ground_truth_rect = np.loadtxt(str(anno_path), delimiter=',', dtype=np.float64) end_frame = ground_truth_rect.shape[0] print(ground_truth_rect.shape) ground_truth_rect = ground_truth_rect[:, [0, 1, 2, 3]] else: print('did not find {}' % anno_path) # anno_path = '{}/{}/init.txt'.format(self.base_path, sequence_name) # try: # ground_truth_rect = np.loadtxt(str(anno_path), dtype=np.float64) # except: # ground_truth_rect = np.loadtxt(str(anno_path), delimiter=',', dtype=np.float64) # print(ground_truth_rect.shape) # ground_truth_rect=ground_truth_rect.reshape(1,4) frames_path = '{}/processed/{}'.format(self.base_path, sequence_name) rgb_frame_list = [ '{frames_path}/{frame}.{ext}'.format(frames_path=frames_path, frame=frame_num, ext=ext) for frame_num in range(end_frame) ] depth_frame_list = [ '{frames_path}/{frame}d.{ext}'.format(frames_path=frames_path, frame=frame_num, ext=ext) for frame_num in range(end_frame) ] if len(ground_truth_rect) == 0: ground_truth_rect = np.zeros((len(rgb_frame_list), 4)) return Sequence(sequence_name, rgb_frame_list, ground_truth_rect, depth_frame_list)
def _construct_sequence(self, sequence_name): sequence_path = sequence_name nz = 8 ext = 'jpg' start_frame = 1 anno_path = '{}/{}/groundtruth.txt'.format(self.base_path, sequence_name) try: gt_all = io.read_file(str(anno_path)) ground_truth_rect = None except: ground_truth_rect = np.loadtxt(str(anno_path), delimiter=',', dtype=np.float64) end_frame = len(gt_all) gt_seg_all = [] for frame_num in range(end_frame): gt_seg = trax.Mask.create(gt_all[frame_num].mask, gt_all[frame_num].offset[0], gt_all[frame_num].offset[1]) gt_seg_all.append(gt_seg.array(1)) frames = [ '{base_path}/{sequence_path}/color/{frame:0{nz}}.{ext}'.format( base_path=self.base_path, sequence_path=sequence_path, frame=frame_num, nz=nz, ext=ext) for frame_num in range(start_frame, end_frame + 1) ] # Convert gt # if ground_truth_rect.shape[1] > 4: # gt_x_all = ground_truth_rect[:, [0, 2, 4, 6]] # gt_y_all = ground_truth_rect[:, [1, 3, 5, 7]] # x1 = np.amin(gt_x_all, 1).reshape(-1,1) # y1 = np.amin(gt_y_all, 1).reshape(-1,1) # x2 = np.amax(gt_x_all, 1).reshape(-1,1) # y2 = np.amax(gt_y_all, 1).reshape(-1,1) # ground_truth_rect = np.concatenate((x1, y1, x2-x1, y2-y1), 1) return Sequence(sequence_name, frames, 'vot', ground_truth_rect, gt_seg_all)
def _construct_sequence(self, sequence_name): class_name = sequence_name.split('-')[0] class_name = '' anno_path = '{}/{}/{}/groundtruth.txt'.format(self.base_path, class_name, sequence_name) ground_truth_rect = load_text(str(anno_path), delimiter=',', dtype=np.float64) occlusion_label_path = '{}/{}/{}/full_occlusion.txt'.format( self.base_path, class_name, sequence_name) # NOTE: pandas backed seems super super slow for loading occlusion/oov masks full_occlusion = load_text(str(occlusion_label_path), delimiter=',', dtype=np.float64, backend='numpy') out_of_view_label_path = '{}/{}/{}/out_of_view.txt'.format( self.base_path, class_name, sequence_name) out_of_view = load_text(str(out_of_view_label_path), delimiter=',', dtype=np.float64, backend='numpy') target_visible = np.logical_and(full_occlusion == 0, out_of_view == 0) frames_path = '{}/{}/{}/img'.format(self.base_path, class_name, sequence_name) frames_list = [ '{}/{:08d}.jpg'.format(frames_path, frame_number) for frame_number in range(1, ground_truth_rect.shape[0] + 1) ] target_class = class_name return Sequence(sequence_name, frames_list, 'lasot', ground_truth_rect.reshape(-1, 4), object_class=target_class, target_visible=target_visible)
def _construct_sequence(self, sequence_info): sequence_path = sequence_info['path'] nz = sequence_info['nz'] ext = sequence_info['ext'] start_frame = sequence_info['startFrame'] end_frame = sequence_info['endFrame'] init_omit = 0 if 'initOmit' in sequence_info: init_omit = sequence_info['initOmit'] frames = [ '{base_path}/{sequence_path}/{frame:0{nz}}.{ext}'.format( base_path=self.base_path, sequence_path=sequence_path, frame=frame_num, nz=nz, ext=ext) for frame_num in range(start_frame + init_omit, end_frame + 1) ] anno_path = '{}/{}'.format(self.base_path, sequence_info['anno_path']) # NOTE: OTB has some weird annos which panda cannot handle #ground_truth_rect = load_text(str(anno_path), delimiter=(',', None), dtype=np.float64, backend='numpy') ground_truth_rect2 = OrderedDict({ 0: [854, 895, 129, 75], 1: [3375, 1172, 114, 83], 2: [1829, 0, 49, 62] }) #ground_truth_rect2 = {('obj_id':0, 'gt':1, 'bboxes':[200,300,20,20]),('obj_id':1, 'gt':1, 'bboxes':[400,500,20,20])} #ground_truth_rect2 #ground_truth_rect2[0] = [1,[200,300,20,20]] #ground_truth_rect2[1] = [1,[400,500,30,20]] return Sequence(sequence_info['name'], frames, 'otb', ground_truth_rect=ground_truth_rect2, object_class=sequence_info['object_class'], multiobj_mode=True, object_ids=[0, 1, 2])
def _construct_sequence(self, sequence_name): anno_path = '{}/{}/groundtruth.txt'.format(self.base_path, sequence_name) ground_truth_rect = load_text(str(anno_path), delimiter=',', dtype=np.float64) frames_path = '{}/{}'.format(self.base_path, sequence_name) frame_list = [ frame for frame in os.listdir(frames_path) if frame.endswith(".jpg") ] frame_list.sort(key=lambda f: int(f[:-4])) frames_list = [ os.path.join(frames_path, frame) for frame in frame_list ] return Sequence(sequence_name, frames_list, 'toolkit', ground_truth_rect.reshape(-1, 4))
def _construct_sequence(self, sequence_info): sequence_path = sequence_info['path'] nz = sequence_info['nz'] ext = sequence_info['ext'] start_frame = sequence_info['startFrame'] end_frame = sequence_info['endFrame'] init_omit = 0 if 'initOmit' in sequence_info: init_omit = sequence_info['initOmit'] frames = ['{base_path}/{sequence_path}/30/{sequence_path}/{frame:0{nz}}.{ext}'.format(base_path=self.base_path, sequence_path=sequence_path, frame=frame_num, nz=nz, ext=ext) for frame_num in range(start_frame+init_omit, end_frame+1)] anno_path = '{}/{}/{}/{}'.format(self.base_path, sequence_info['anno_path'][:-4], 30, sequence_info['anno_path']) try: # ground_truth_rect = np.loadtxt(str(anno_path), dtype=np.float64) ground_truth_rect = np.loadtxt(anno_path, str) ground_truth_rect = ground_truth_rect[:, 1:5].astype(float) # [left, top, right, bottom] ground_truth_rect[:, 2:] -= ground_truth_rect[:, :2] # [left, top, width, height] except: ground_truth_rect = np.loadtxt(str(anno_path), delimiter=',', dtype=np.float64) if not len(frames) == len(ground_truth_rect): if abs(len(ground_truth_rect) / len(frames) - 8) < 1: ground_truth_rect = ground_truth_rect[0::8, :] diff = abs(len(frames) - len(ground_truth_rect)) if diff > 0 and diff <= 1: n = min(len(frames), len(ground_truth_rect)) ground_truth_rect = ground_truth_rect[:n] frames = frames[:n] # frames = ['{base_path}/{sequence_path}/{frame:0{nz}}.{ext}'.format(base_path=self.base_path, # sequence_path=sequence_path, frame=frame_num, nz=nz, ext=ext) for frame_num in range(start_frame+init_omit, end_frame+1)] # anno_path = '{}/{}'.format(self.base_path, sequence_info['anno_path']) # ground_truth_rect = load_text(str(anno_path), delimiter='\t', dtype=np.float64) return Sequence(sequence_info['name'], frames, 'nfs', ground_truth_rect[init_omit:,:], object_class=sequence_info['object_class'])
def _construct_sequence(self, sequence_name): sequence_path = sequence_name #nz = 8 ext = 'png' start_frame = 1 anno_path = '{}/{}/{}.txt'.format(self.base_path, sequence_name, sequence_name) if os.path.exists(str(anno_path)): try: ground_truth_rect = np.loadtxt(str(anno_path), dtype=np.float64) except: ground_truth_rect = np.loadtxt(str(anno_path), delimiter=',', dtype=np.float64) end_frame = ground_truth_rect.shape[0] ground_truth_rect = ground_truth_rect[:, [0, 1, 2, 3]] else: #print('ptbdataset, no full groundtruth file, use init file') anno_path = '{}/{}/init.txt'.format(self.base_path, sequence_name) try: ground_truth_rect = np.loadtxt(str(anno_path), dtype=np.float64) except: ground_truth_rect = np.loadtxt(str(anno_path), delimiter=',', dtype=np.float64) #print(ground_truth_rect.shape) ground_truth_rect = ground_truth_rect.reshape(1, 4) # frames = ['{base_path}/{sequence_path}/rgb/{frame:0{nz}}.{ext}'.format(base_path=self.base_path, # sequence_path=sequence_path, frame=frame_num, nz=nz, ext=ext) # for frame_num in range(start_frame, end_frame+1)] frames_path = '{}/{}/rgb'.format(self.base_path, sequence_path) rgb_frame_list = [ frame for frame in os.listdir(frames_path) if frame.endswith(ext) ] #print(rgb_frame_list[0].split('-')[2][0:-4]) rgb_frame_list.sort(key=lambda f: int(f.split('-')[2][0:-4])) rgb_frame_list = [ os.path.join(frames_path, frame) for frame in rgb_frame_list ] #print('ptbdataset, rgb_frame_list[0] %s' % rgb_frame_list[0]) depth_frames_path = '{}/{}/depth'.format(self.base_path, sequence_path) depth_frame_list = [ frame for frame in os.listdir(depth_frames_path) if frame.endswith(ext) ] depth_frame_list.sort(key=lambda f: int(f.split('-')[2][0:-4])) depth_frame_list = [ os.path.join(depth_frames_path, frame) for frame in depth_frame_list ] if len(ground_truth_rect) == 0: ground_truth_rect = np.zeros((len(rgb_frame_list), 4)) #print([rgb_frame_list[0], depth_frame_list[0]]) if self.use_regis_synch_file: seq_both_list = [ seq for seq in os.listdir(self.regis_synch_dir + '/both_sync_and_reg') if seq == sequence_name ] seq_reg_list = [ seq for seq in os.listdir(self.regis_synch_dir + '/only_reg') if seq == sequence_name ] seq_syn_list = [ seq for seq in os.listdir(self.regis_synch_dir + '/only_sync') if seq == sequence_name ] #print(len(seq_both_list), len(seq_reg_list), len(seq_syn_list)) if len(seq_both_list) > 0: mat = scipy.io.loadmat(self.regis_synch_dir + '/both_sync_and_reg/' + sequence_name + '/FrameID_sync.mat') ids_sync = mat['FrameID_sync'] ids_sync = list(ids_sync.flatten()) name_list = [ frame for frame in os.listdir(depth_frames_path) if frame.endswith(ext) ] name_list.sort(key=lambda f: int(f.split('-')[2][0:-4])) reordered_name_list = [name_list[id - 1] for id in ids_sync] depth_frame_list = [ os.path.join( self.regis_synch_dir + '/both_sync_and_reg/' + sequence_name + '/registered_depth', frame) for frame in reordered_name_list ] if len(seq_reg_list) > 0: depth_frame_list = [ frame for frame in os.listdir(depth_frames_path) if frame.endswith(ext) ] depth_frame_list.sort(key=lambda f: int(f.split('-')[2][0:-4])) only_reg_depth_dir = self.regis_synch_dir + '/only_reg/' + sequence_name + '/registered_depth' depth_frame_list = [ os.path.join(only_reg_depth_dir, frame) for frame in depth_frame_list ] # depth_frame_list = [] # for frame in depth_frame_list: # print(frame) # if os.path.exists(os.path.join(only_reg_depth_dir, frame)): # depth_frame_list.append(os.path.join(only_reg_depth_dir, frame)) # else: # depth_frame_list.append(os.path.join(depth_frames_path, frame)) if len(seq_syn_list) > 0 and sequence_name != 'bear_back': mat = scipy.io.loadmat(self.regis_synch_dir + '/only_sync/' + sequence_name + '/FrameID_sync.mat') ids_sync = mat['FrameID_sync'] ids_sync = list(ids_sync.flatten()) name_list = [ frame for frame in os.listdir(depth_frames_path) if frame.endswith(ext) ] name_list.sort(key=lambda f: int(f.split('-')[2][0:-4])) reordered_name_list = [name_list[id - 1] for id in ids_sync] depth_frame_list = [ os.path.join(depth_frames_path, frame) for frame in reordered_name_list ] return Sequence(sequence_name, rgb_frame_list, ground_truth_rect, depth_frame_list)
def _construct_sequence(self, sequence_name): sequence_path = sequence_name #nz = 8 ext = 'png' start_frame = 1 anno_path = '{}/{}/{}.txt'.format(self.base_path, sequence_name, 'GT') if os.path.exists(str(anno_path)): try: ground_truth_rect = np.loadtxt(str(anno_path), dtype=np.float64) except: ground_truth_rect = np.loadtxt(str(anno_path), delimiter=',', dtype=np.float64) end_frame = ground_truth_rect.shape[0] ground_truth_rect = ground_truth_rect[:, [0, 1, 2, 3]] else: #print('ptbdataset, no full groundtruth file, use init file') anno_path = '{}/{}/init.txt'.format(self.base_path, sequence_name) try: ground_truth_rect = np.loadtxt(str(anno_path), dtype=np.float64) except: ground_truth_rect = np.loadtxt(str(anno_path), delimiter=',', dtype=np.float64) #print(ground_truth_rect.shape) ground_truth_rect = ground_truth_rect.reshape(1, 4) # frames = ['{base_path}/{sequence_path}/rgb/{frame:0{nz}}.{ext}'.format(base_path=self.base_path, # sequence_path=sequence_path, frame=frame_num, nz=nz, ext=ext) # for frame_num in range(start_frame, end_frame+1)] frames_path = '{}/{}/RGB'.format(self.base_path, sequence_path) rgb_frame_list = [ frame for frame in os.listdir(frames_path) if frame.endswith(ext) ] rgb_frame_list.sort(key=lambda f: int(f[0:-4])) rgb_frame_list = [ os.path.join(frames_path, frame) for frame in rgb_frame_list ] #print('ptbdataset, rgb_frame_list[0] %s' % rgb_frame_list[0]) depth_frames_path = '{}/{}/Depth'.format(self.base_path, sequence_path) depth_frame_list = [ frame for frame in os.listdir(depth_frames_path) if frame.endswith(ext) ] depth_frame_list.sort(key=lambda f: int(f[0:-4])) depth_frame_list = [ os.path.join(depth_frames_path, frame) for frame in depth_frame_list ] if len(ground_truth_rect) == 0: ground_truth_rect = np.zeros((len(rgb_frame_list), 4)) return Sequence(sequence_name, rgb_frame_list, ground_truth_rect, depth_frame_list)