def main(): n1 = 50 record_file = 'segment-8513241054672631743_115_960_135_960_with_camera_labels' record = tf.data.TFRecordDataset('data/train/' + record_file + '.tfrecord', compression_type='') for frame_num, frame_data in enumerate(record): if frame_num == n1: frame = dataset_pb2.Frame() frame.ParseFromString(bytearray(frame_data.numpy())) image1 = extract_image(frame) elif frame_num == n1 + 1: frame = dataset_pb2.Frame() frame.ParseFromString(bytearray(frame_data.numpy())) image2 = extract_image(frame) break flows = torch.as_tensor(np.load('flow/train/' + record_file + '.npy'), dtype=torch.float32) flow = flows[n1 + 1] plt.imshow((torch.squeeze(image1, 0).permute(1, 2, 0) / 255)) plt.savefig('im1') plt.imshow((torch.squeeze(image2, 0).permute(1, 2, 0) / 255)) plt.savefig('im2') device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") image1 = image1.to(device) flow = flow.to(device) warped = warp(torch.unsqueeze(image1, 0), torch.unsqueeze(flow, 0)) plt.imshow((torch.squeeze(warped, 0).permute(1, 2, 0) / 255).cpu()) plt.savefig('warped12')
def cvt(self): """ convert dataset from Waymo to KITTI Args: return: """ tf.enable_eager_execution() file_num = 1 frame_num = 1 print("Start converting ...") for file_name in tqdm.tqdm(self.__file_names): dataset = tf.data.TFRecordDataset(file_name, compression_type='') for data in dataset: frame = open_dataset.Frame() frame.ParseFromString(bytearray(data.numpy())) if LOCATION_FILTER_FLAG and frame.context.stats.location not in LOCATION_NAME: continue self.save_image(frame, frame_num) self.save_calib(frame, frame_num) self.save_lidar(frame, frame_num) self.save_label(frame, frame_num) print("Frame number {0}".format(frame_num)) frame_num += 1 print("File number {0}".format(file_num)) file_num += 1 print("\nFinished!")
def tfrecord_to_mp4(tfrecord_path, out_path): """ Converts single tfrecord file to video files. One video file per camera is placed in out_path. """ ds = tf.data.TFRecordDataset(args.path) fourcc = cv2.VideoWriter_fourcc(*'mp4v') videos = [None] * 5 for data in ds: frame = dataset_pb2.Frame() frame.ParseFromString(bytearray(data.numpy())) for image in frame.images: img = tf.io.decode_jpeg(image.image).numpy() if videos[image.name - 1] is None: video_path = os.path.join( out_path, '{}_{}.mp4'.format(frame.context.name, image.name)) videos[image.name - 1] = cv2.VideoWriter( video_path, fourcc, 20.0, (img.shape[1], img.shape[0])) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) videos[image.name - 1].write(img) for video in videos: video.release()
def process_tfr(path, data_dir): """ process a Waymo tf record into a tf api tf record args: - path [str]: path to the Waymo tf record file - data_dir [str]: path to the destination directory """ # create processed data dir dest = os.path.join(data_dir, 'processed') os.makedirs(dest, exist_ok=True) file_name = os.path.basename(path) logger.info(f'Processing {path}') writer = tf.python_io.TFRecordWriter(f'{dest}/{file_name}') dataset = tf.data.TFRecordDataset(path, compression_type='') for idx, data in enumerate(dataset): # we are only saving every 10 frames to reduce the number of similar # images. Remove this line if you have enough space to work with full # temporal resolution data. if idx % 10 == 0: frame = open_dataset.Frame() frame.ParseFromString(bytearray(data.numpy())) encoded_jpeg, annotations = parse_frame(frame) filename = file_name.replace('.tfrecord', f'_{idx}.tfrecord') tf_example = create_tf_example(filename, encoded_jpeg, annotations) writer.write(tf_example.SerializeToString()) writer.close()
def showCam(filename): dataset = tf.data.TFRecordDataset(filename, compression_type='') for data in dataset: frame = open_dataset.Frame() frame.ParseFromString(bytearray(data.numpy())) names = [] for i in range(len(frame.images)): image = frame.images[i] nparr = np.frombuffer(image.image, np.uint8) img_np = cv2.imdecode(nparr, cv2.IMREAD_COLOR) if i == 0: img_concat = img_np else: img_concat = np.concatenate((img_concat, img_np), axis=0) name = open_dataset.CameraName.Name.Name(image.name) names.append(name) cv2.namedWindow(', '.join(names), cv2.WINDOW_NORMAL) cv2.resizeWindow(', '.join(names), 400, 5*300) cv2.imshow(', '.join(names), img_concat) if cv2.waitKey(1) & 0xFF == ord('q'): cv2.destroyAllWindows() break
def extract_frame( frames_path): #, outdir_img, class_mapping, resize_ratio=1.0): dataset = tf.data.TFRecordDataset(frames_path, compression_type='') #id_dict = {} #bboxes_all = {} #scores_all = {} #cls_inds_all = {} #track_ids_all = {} #if not os.path.exists(outdir_img): # os.mkdir(outdir_img) for fidx, data in enumerate(dataset): frame = open_dataset.Frame() frame.ParseFromString(bytearray(data.numpy())) (range_images, camera_projections, range_image_top_pose) = ( frame_utils.parse_range_image_and_camera_projection(frame)) final_frame_dict = {} pose = frame.pose final_frame_dict["pose"] = pose for i in range(5): final_frame_dict[str(i + 1) + "_image"] = frame.images[i] final_frame_dict[ str(i + 1) + "_calibration"] = frame.context.camera_calibrations[i] with open( "contexts/{}.{}.pickle".format(frame.context.name, frame.timestamp_micros), "wb") as f: pickle.dump(final_frame_dict, f, protocol=pickle.HIGHEST_PROTOCOL)
def convert_one(self, file_idx): """Convert action for single file. Args: file_idx (int): Index of the file to be converted. """ pathname = self.tfrecord_pathnames[file_idx] print("Convert: fileindex:", file_idx) print("Current path:", pathname) c_start = time.time() dataset = tf.data.TFRecordDataset(pathname, compression_type='') for frame_idx, data in enumerate(dataset): frame = open_dataset.Frame() frame.ParseFromString(bytearray(data.numpy())) if (self.selected_waymo_locations is not None and frame.context.stats.location not in self.selected_waymo_locations): continue self.save_image(frame, file_idx, frame_idx) self.save_calib(frame, file_idx, frame_idx) self.save_lidar(frame, file_idx, frame_idx) self.save_pose(frame, file_idx, frame_idx) if not self.test_mode: self.save_label(frame, file_idx, frame_idx) print(f"convert one Execution time: { time.time() - c_start }")
def tfRecordToBin(data_file_name, data_type): if data_type == 'vehicle': data_type_label = label_pb2.Label.TYPE_VEHICLE elif data_type == 'pedestrian': data_type_label = label_pb2.Label.TYPE_PEDESTRIAN elif data_type == 'cyclist': data_type_label = label_pb2.Label.TYPE_CYCLIST else: print("Usage: python tfRecordDataToLabel.py data.tfrecord vehicle") sys.exit(1) result_file_name = data_file_name[:-9] + "_" + data_type + "_gt" + '.bin' objs = metrics_pb2.Objects() dataset = tf.data.TFRecordDataset(data_file_name, compression_type='') for data in dataset: frame = dataset_pb2.Frame() frame.ParseFromString(bytearray(data.numpy())) for frame_obj in frame.laser_labels: if not frame_obj.type == data_type_label: continue obj = metrics_pb2.Object() obj.object.box.CopyFrom(frame_obj.box) obj.object.type = frame_obj.type obj.object.id = frame_obj.id obj.context_name = frame.context.name obj.frame_timestamp_micros = frame.timestamp_micros objs.objects.append(obj) with open(result_file_name, 'wb') as f: f.write(objs.SerializeToString())
def extract_frame(frames_path, outdir_img, class_mapping, resize_ratio=1.0): dataset = tf.data.TFRecordDataset(frames_path, compression_type='') id_dict = {} bboxes_all = {} scores_all = {} cls_inds_all = {} track_ids_all = {} if not os.path.exists(outdir_img): os.mkdir(outdir_img) for fidx, data in enumerate(dataset): frame = open_dataset.Frame() frame.ParseFromString(bytearray(data.numpy())) (range_images, camera_projections, range_image_top_pose) = ( frame_utils.parse_range_image_and_camera_projection(frame)) time = frame.context.stats.time_of_day weather = frame.context.stats.weather for i in range(len(frame.images)): context_name = frame.context.name ftm = frame.timestamp_micros cam_name = frame.images[i].name im = tf.image.decode_jpeg( frame.images[i].image).numpy()[:, :, ::-1] target_size = (int(im.shape[1] * resize_ratio), int(im.shape[0] * resize_ratio)) im = cv2.resize(im, target_size) cv2.imwrite( outdir_img + '/{}.{}.{}.png'.format(context_name, ftm, cam_name), im)
def make_gt_file_native(data_path, gt_save_path, view=dataset_pb2.CameraName.FRONT): scene_files = sorted(os.listdir(data_path)) gt_objects = metrics_pb2.Objects() for scene_num, record_file in enumerate(scene_files): record = tf.data.TFRecordDataset(os.path.join(data_path, record_file), compression_type='') for frame_data in record: frame = dataset_pb2.Frame() frame.ParseFromString(bytearray(frame_data.numpy())) for camera_labels in frame.camera_labels: if camera_labels.name != view: continue for label in camera_labels.labels: gt_objects.objects.append(create_gt_obj( frame, label, view)) print("Finished scene", scene_num) f = open(gt_save_path, 'wb') f.write(gt_objects.SerializeToString()) f.close()
def point_cloud_extractor(i, filename, lidar): FileName = filename dataset = tf.data.TFRecordDataset(FileName, compression_type='') for data in dataset: i_str = '{0:06}'.format(i) frame = open_dataset.Frame() frame.ParseFromString(bytearray(data.numpy())) (range_images, range_image_top_pose) = parse_range_image_and_camera_projection(frame) points, reflectence = convert_range_image_to_point_cloud( frame, range_images, range_image_top_pose) points_all = np.concatenate(points, axis=0) reflectence_all = np.concatenate(reflectence, axis=0) point_cloud = np.column_stack((points_all, reflectence_all)) file_path = os.path.join(lidar, "%s.bin" % (i_str)) point_cloud.tofile(file_path) i = i + 1 return i
def extract_onesegment_toframe(fileidx, tfrecord_pathnames, step): segment_path = tfrecord_pathnames[fileidx] c_start = time.time() print( f'extracting {fileidx}, path: {segment_path}, currenttime: {c_start}') dataset = tf.data.TFRecordDataset(str(segment_path), compression_type='') framesdict = {} # [] for i, data in enumerate(dataset): if i % step != 0: # Downsample continue # print('.', end='', flush=True) #progress bar frame = dataset_pb2.Frame() frame.ParseFromString(bytearray(data.numpy())) # get one frame # A unique name that identifies the frame sequence context_name = frame.context.name # print('context_name:', context_name)#14824622621331930560_2395_420_2415_420, same to the tfrecord file name frame_timestamp_micros = str(frame.timestamp_micros) # print(frame_timestamp_micros) # frames.append(frame) framesdict[frame_timestamp_micros] = frame return framesdict
def loadWaymoTestFrames(PATH): #train_folders = ["training_0005","training_0004","training_0003","training_0002","training_0001","training_0000"]#["training_0001"]# ["training_0000", "training_0001"] test_folders = [ "testing_0007", "testing_0006", "testing_0005", "testing_0004", "testing_0003", "testing_0002", "testing_0001", "testing_0000" ] data_files = [ path for x in test_folders for path in glob(os.path.join(PATH, x, "*.tfrecord")) ] print(data_files) #all TFRecord file list print(len(data_files)) dataset = [ tf.data.TFRecordDataset(FILENAME, compression_type='') for FILENAME in data_files ] #create a list of dataset for each TFRecord file frames = [ ] #store all frames = total number of TFrecord files * 40 frame(each TFrecord) for i, data_file in enumerate(dataset): print("Datafile: ", data_files[i]) #Each TFrecord file for idx, data in enumerate( data_file ): #Create frame based on Waymo API, 199 frames per TFrecord (20s, 10Hz) # if idx % 5 != 0: #Downsample every 5 images, reduce to 2Hz, total around 40 frames # continue frame = open_dataset.Frame() frame.ParseFromString(bytearray(data.numpy())) frames.append(frame) return frames
def loadRecord(filepath, objects): nFrames = 0 global nObjects print("loadRecord: " + filepath) dataset = tf.data.TFRecordDataset(filepath, compression_type='') for data in dataset: print("enter first loop") nFrames = nFrames + 1 nObjects = 0 frame = dataset_pb2.Frame() frame.ParseFromString(bytearray(data.numpy())) #print(frame.camera_labels) for index, img in enumerate(frame.images): print("enter second loop") #print(img.name) #print(str(img.name)) f = open(str(img.name) + ".jpg", "wb+") #print(str(img.name)+".jpg") f.write(img.image) print("performing detection:") performDetect(objects, frame, str(img.name) + ".jpg") f.close() os.remove(str(img.name) + '.jpg') #print(objects) print("objects in image:" + str(nObjects)) break if (nFrames >= 3): break print(nFrames) return nFrames
def main(argv): # Code to partition images based on Generative Factors tf.compat.v1.enable_eager_execution() global train_folder global folder_path if not os.path.exists(folder_path): os.mkdir(folder_path) for folder in train_folders: train_folder = folder path_to_data = train_dir + folder global image_id image_id = 0 for root, dirs, files in os.walk(path_to_data): for file in files: if file.startswith( "segment"): # avoid license file inside the folder filepath = os.path.join(root, file) print("examine : " + filepath) dataset = tf.data.TFRecordDataset(filepath, compression_type='') for data in dataset: frame = open_dataset.Frame() # instance of a frame frame.ParseFromString(bytearray(data.numpy())) examine_frame(frame) tf.compat.v1.disable_eager_execution()
def convert_one(self, file_idx): pathname = self.tfrecord_pathnames[file_idx] dataset = tf.data.TFRecordDataset(pathname, compression_type='') for frame_idx, data in enumerate(dataset): frame = open_dataset.Frame() frame.ParseFromString(bytearray(data.numpy())) if selected_waymo_locations is not None and frame.context.stats.location not in selected_waymo_locations: continue # save images self.save_image(frame, file_idx, frame_idx) # parse calibration files self.save_calib(frame, file_idx, frame_idx) # parse point clouds self.save_lidar(frame, file_idx, frame_idx) # parse label files self.save_label(frame, file_idx, frame_idx) # parse pose files self.save_pose(frame, file_idx, frame_idx)
def read_tfrecord(): dataset = tf.data.TFRecordDataset(tfrecord_file_name, compression_type='') for data in dataset: frame = open_dataset.Frame() frame.ParseFromString(bytearray(data.numpy())) # print(frame) # print('\n\n\n\n') # print(frame.context) # print(np.array(frame.pose.transform).reshape(4,4)) for obj in frame.laser_labels: print(obj) # print(obj.num_lidar_points_in_box) # print(frame.context.name) # print(type(frame)) # print(type(frame.laser_labels[0])) # # print([i.num_lidar_points_in_box for i in frame.laser_labels]) # print([i.type for i in frame.laser_labels]) # for obj in frame.laser_labels: # print(obj.num_lidar_points_in_box) assert 0
def filter_frame_points(self, dataset): """ Return dict that maps from object type ids to point clouds. Value for each key is a list of numpy arrays, where each numpy array containts points for a single 3D bbox. """ for frame_num, data in tqdm.tqdm(enumerate(dataset)): self.frame_num = frame_num frame = open_dataset.Frame() frame.ParseFromString(bytearray(data.numpy())) frame_pts = self.frame_points(frame) for obj_code in self.obj_codes: boxes, metadata = self.frame_boxes_3D(frame, obj_code) if len(boxes): for i, mask in enumerate( tf.transpose( box_utils.is_within_box_3d(frame_pts, np.array(boxes)))): points_number = mask.numpy().sum() if points_number >= self.min_pts_threshold: self.bbox_dict[obj_code].append( tf.boolean_mask(frame_pts, mask).numpy()) metadata[i].append(points_number) self.metadata_dict[obj_code].append( np.array(metadata[i]))
def image_extractor(i ,filename, Front, Front_left, Side_left, Front_right, Side_right): FileName = filename dataset = tf.data.TFRecordDataset(FileName, compression_type='') for data in dataset: frame = open_dataset.Frame() frame.ParseFromString(bytearray(data.numpy())) for index, image in enumerate(frame.images): i_str = '{0:06}'.format(i) ima = tf.image.decode_jpeg(image.image).numpy() if index == 0: cv2.imwrite(os.path.join(Front, "%s.png")%(i_str), cv2.cvtColor(ima, cv2.COLOR_RGB2BGR)) continue if index == 1: cv2.imwrite(os.path.join(Front_left, "%s.png")%(i_str), cv2.cvtColor(ima, cv2.COLOR_RGB2BGR)) continue if index == 2: cv2.imwrite(os.path.join(Side_left, "%s.png")%(i_str), cv2.cvtColor(ima, cv2.COLOR_RGB2BGR)) continue if index == 3: cv2.imwrite(os.path.join(Front_right, "%s.png")%(i_str), cv2.cvtColor(ima, cv2.COLOR_RGB2BGR)) continue if index == 4: cv2.imwrite(os.path.join(Side_right, "%s.png")%(i_str), cv2.cvtColor(ima, cv2.COLOR_RGB2BGR)) # continue i = i+ 1 return i
def main(token, process_num, data_folder, output_folder): tf_records = os.listdir(data_folder) tf_records = [x for x in tf_records if 'tfrecord' in x] tf_records = sorted(tf_records) for record_index, tf_record_name in enumerate(tf_records): if record_index % process_num != token: continue print('starting for ego info ', record_index + 1, ' / ', len(tf_records), ' ', tf_record_name) FILE_NAME = os.path.join(data_folder, tf_record_name) dataset = tf.data.TFRecordDataset(FILE_NAME, compression_type='') segment_name = tf_record_name.split('.')[0] # if os.path.exists(os.path.join(output_folder, '{}.npz'.format(segment_name))): # continue frame_num = 0 ego_infos = dict() for data in dataset: frame = open_dataset.Frame() frame.ParseFromString(bytearray(data.numpy())) ego_info = np.reshape(np.array(frame.pose.transform), [4, 4]) ego_infos[str(frame_num)] = ego_info frame_num += 1 if frame_num % 10 == 0: print('record {:} / {:} frame number {:}'.format( record_index + 1, len(tf_records), frame_num)) print('{:} frames in total'.format(frame_num)) np.savez_compressed( os.path.join(output_folder, "{}.npz".format(segment_name)), **ego_infos)
def process_tfr(path): """ process a waymo tf record into a tf api tf record """ # create processed data dir file_name = os.path.basename(path) logging.info(f'\nProcessing {path}\n') writer = tf.python_io.TFRecordWriter(f'output/{file_name}') dataset = tf.data.TFRecordDataset(path, compression_type='') for idx, data in enumerate(dataset): frame = open_dataset.Frame() frame.ParseFromString(bytearray(data.numpy())) encoded_jpeg, annotations = parse_frame(frame) filename = file_name.replace('.tfrecord', f'_{idx}.tfrecord') tf_example = create_tf_example(filename, encoded_jpeg, annotations) writer.write(tf_example.SerializeToString()) writer.close() logging.info(f'\nFinish {path}\n')
def convert_one(self, file_idx): """Convert action for single file. Args: file_idx (int): Index of the file to be converted. """ pathname = self.tfrecord_pathnames[file_idx] dataset = tf.data.TFRecordDataset(pathname, compression_type='') for frame_idx, data in enumerate(dataset): frame = dataset_pb2.Frame() frame.ParseFromString(bytearray(data.numpy())) if (self.selected_waymo_locations is not None and frame.context.stats.location not in self.selected_waymo_locations): continue # self.save_image(frame, file_idx, frame_idx) self.save_calib(frame, file_idx, frame_idx) self.save_lidar(frame, file_idx, frame_idx) self.save_pose(frame, file_idx, frame_idx) if not self.test_mode: self.save_label(frame, file_idx, frame_idx)
def __init__(self, record_file): record = tf.data.TFRecordDataset(record_file, compression_type='') self.frames = [] for frame_data in record: frame = dataset_pb2.Frame() frame.ParseFromString(bytearray(frame_data.numpy())) self.frames.append(frame)
def convert_tfrecord(ntqdm, input_file, output_path: Path, zip_output=False, delele_input=True): output_path.mkdir(exist_ok=True, parents=True) dataset = tf.data.TFRecordDataset(str(input_file), compression_type='') archive = None # parse compression compression = None if zip_output: if zip_output == "deflated": compression = zipfile.ZIP_DEFLATED elif zip_output == "bzip2": compression = zipfile.ZIP_BZIP2 elif zip_output == "lzma": compression = zipfile.ZIP_LZMA else: compression = zipfile.ZIP_STORED disp = os.path.split(input_file)[1] disp = "Converting %s..." % disp[8:disp.find("_")] for idx, data in tqdm(enumerate(dataset), desc=disp, position=ntqdm, unit="frames", dynamic_ncols=True, leave=False): if idx > 9999: raise RuntimeError( "Frame index is larger than file name capacity!") frame = dataset_pb2.Frame() frame.ParseFromString(bytearray(data.numpy())) if archive is None: if zip_output: archive = zipfile.ZipFile(output_path / (frame.context.name + ".zip"), "w", compression=compression) else: archive = output_path / frame.context.name archive.mkdir(exist_ok=True) save_timestamp(frame, idx, archive) save_image(frame, idx, archive) save_point_cloud(frame, idx, archive) save_labels(frame, idx, archive) save_pose(frame, idx, archive) save_context(frame, idx, archive) # save metadata at last if archive is not None and zip_output: archive.close() if delele_input: # delete intermediate file os.remove(input_file) return idx
def threaded_laser_image_extraction(self, datasetAsList, range_value): frame = open_dataset.Frame() for frameIdx in range_value: frame.ParseFromString(datasetAsList[frameIdx]) self.extract_laser(frameIdx, frame) self.extract_laser_labels(frameIdx, frame)
def read_frame_waymo_segment(tf_record_path, frame_index=0): dataset = tf.data.TFRecordDataset(tf_record_path, compression_type='') frame = None for i, data in enumerate(dataset): if i == frame_index: frame = open_dataset.Frame() frame.ParseFromString(bytearray(data.numpy())) return frame
def _parse_frame(self): self.frames = list() for data in self.dataset: frame = open_dataset.Frame() frame.ParseFromString(bytearray(data.numpy())) self.frames.append(frame) if(self.debug): break
def load_tfrecord(self,idx): dataset = tf.data.TFRecordDataset(self.filename, compression_type='') frame = None for data in dataset: frame = open_dataset.Frame() frame.ParseFromString(bytearray(data.numpy())) break return frame
def extract(i): FILENAME = segments[i] run = FILENAME.split('segment-')[-1].split('.')[0] out_base_dir = sys.argv[2] + '/%s/' % run if not os.path.exists(out_base_dir): os.makedirs(out_base_dir) dataset = tf.data.TFRecordDataset(FILENAME, compression_type='') print(FILENAME) pc, pc_c = [], [] camID2extr_v2c = {} camID2intr = {} all_static_pc = [] for frame_cnt, data in enumerate(dataset): if frame_cnt % 2 != 0: continue ### Set the sampling rate here print('frame ', frame_cnt) frame = open_dataset.Frame() frame.ParseFromString(bytearray(data.numpy())) extr_laser2v = np.array( frame.context.laser_calibrations[0].extrinsic.transform).reshape( 4, 4) extr_v2w = np.array(frame.pose.transform).reshape(4, 4) if frame_cnt == 0: for k in range(len(frame.context.camera_calibrations)): cameraID = frame.context.camera_calibrations[k].name extr_c2v =\ np.array(frame.context.camera_calibrations[k].extrinsic.transform).reshape(4, 4) extr_v2c = np.linalg.inv(extr_c2v) camID2extr_v2c[frame.images[k].name] = extr_v2c fx = frame.context.camera_calibrations[k].intrinsic[0] fy = frame.context.camera_calibrations[k].intrinsic[1] cx = frame.context.camera_calibrations[k].intrinsic[2] cy = frame.context.camera_calibrations[k].intrinsic[3] k1 = frame.context.camera_calibrations[k].intrinsic[4] k2 = frame.context.camera_calibrations[k].intrinsic[5] p1 = frame.context.camera_calibrations[k].intrinsic[6] p2 = frame.context.camera_calibrations[k].intrinsic[7] k3 = frame.context.camera_calibrations[k].intrinsic[8] camID2intr[frame.images[k].name] = np.array([[fx, 0, cx], [0, fy, cy], [0, 0, 1]]) # lidar point cloud (range_images, camera_projections, range_image_top_pose) = \ frame_utils.parse_range_image_and_camera_projection(frame) points, cp_points = frame_utils.convert_range_image_to_point_cloud( frame, range_images, camera_projections, range_image_top_pose) points_all = np.concatenate(points, axis=0) np.save('%s/frame_%03d.npy' % (out_base_dir, frame_cnt), points_all) datalist.append( os.path.abspath('%s/frame_%03d.npy' % (out_base_dir, frame_cnt)))
def parse_tfrecord_to_frame(tfrecord_file): tfrecord = FrameParser.parse_tfrecord(tfrecord_file) for data in tfrecord: frame = dataset_pb2.Frame() frame.ParseFromString(bytearray(data.numpy())) frame.images.sort(key=lambda image: image.name) frame.camera_labels.sort(key=lambda label: label.name) frame.lasers.sort(key=lambda laser: laser.name) yield frame