diff --git a/generate_sequential.py b/generate_sequential.py index 491da98..7269d17 100755 --- a/generate_sequential.py +++ b/generate_sequential.py @@ -9,7 +9,7 @@ import shutil from numpy.linalg import inv import struct - +import time def parse_calibration(filename): """ read calibration file with given filename @@ -69,6 +69,8 @@ def parse_poses(filename, calibration): if __name__ == '__main__': + start_time = time.time() + parser = argparse.ArgumentParser("./generate_sequential.py") parser.add_argument( '--dataset', @@ -151,47 +153,45 @@ def parse_poses(filename, calibration): # read scan and labels, get pose scan_filename = os.path.join(input_folder, "velodyne", f) scan = np.fromfile(scan_filename, dtype=np.float32) + scan = scan.reshape((-1, 4)) - label_filename = os.path.join(input_folder, "labels", - os.path.splitext(f)[0] + ".label") + label_filename = os.path.join(input_folder, "labels", os.path.splitext(f)[0] + ".label") labels = np.fromfile(label_filename, dtype=np.uint32) labels = labels.reshape((-1)) # convert points to homogenous coordinates (x, y, z, 1) - points = np.ones((scan.shape[0], 4)) + points = np.ones((scan.shape)) points[:, 0:3] = scan[:, 0:3] remissions = scan[:, 3] pose = poses[i] - # write output files - out_points = open(os.path.join(velodyne_folder, f), "wb") - out_labels = open( - os.path.join(labels_folder, - os.path.splitext(f)[0] + ".label"), "wb") + # prepare single numpy array for all points that can be written at once. + num_concat_points = points.shape[0] + num_concat_points += sum([past["points"].shape[0] for past in history]) + concated_points = np.zeros((num_concat_points * 4), dtype = np.float32) + concated_labels = np.zeros((num_concat_points), dtype = np.uint32) - arr = [struct.pack('= FLAGS.sequence_length: history.pop() - out_points.close() - out_labels.close() - if 100.0 * i / len(scan_files) >= progress: print(".", end="", flush=True) progress = progress + 10 print("finished.") + + + print("execution time: {}".format(time.time() - start_time))