From ab5a6734d54330e2579708364182bcd429163341 Mon Sep 17 00:00:00 2001 From: GiordanoLaminetti Date: Sun, 18 Apr 2021 23:23:25 +0200 Subject: [PATCH] format with Black --- slampy.py | 4 +-- utils.py | 91 +++++++++++++++++++++++++++---------------------------- 2 files changed, 47 insertions(+), 48 deletions(-) diff --git a/slampy.py b/slampy.py index 33563f2..2ac23db 100644 --- a/slampy.py +++ b/slampy.py @@ -94,7 +94,7 @@ def process_image_stereo(self, image_left, image_right, tframe): """ self.image_shape = image_left.shape self.slam.process_image_stereo(image_left, image_right, tframe) - self.image = image + self.image = image_left if self.get_state() == State.OK: self.pose_array.append(self.get_pose_to_target()) return self.get_state() @@ -141,7 +141,7 @@ def process_image_imu_stereo(self, image_left, image_right, tframe, imu): """ self.image_shape = image_left.shape self.slam.process_image_imu_stereo(image_left, image_right, tframe, imu) - self.image = image + self.image = image_left if self.get_state() == State.OK: self.pose_array.append(self.get_pose_to_target()) return self.get_state() diff --git a/utils.py b/utils.py index b71b3ee..15d71c3 100644 --- a/utils.py +++ b/utils.py @@ -232,7 +232,7 @@ def save_pose_txt(args, name, pose): """ pose_file_path = os.path.join(args.dest, "pose.txt") fp = open(pose_file_path, "a") - pose34 = pose[:3] + pose34 = pose[:3] fp.write(name) for row in pose34: fp.write(" ") @@ -242,31 +242,28 @@ def save_pose_txt(args, name, pose): fp.close() - - def save_pose_and_times_txt(args, name, pose): """Save pose and time in two different txt files.""" - + time_file_path = os.path.join(args.dest, "times.txt") pose_file_path = os.path.join(args.dest, "pose.txt") fd = open(time_file_path, "a") fp = open(pose_file_path, "a") - pose34 = pose[:3] + pose34 = pose[:3] fd.write(name) fd.write("\n") fd.close() - line="" - for row in pose34: - line+=(" ".join(str(round(i, 10)) for i in row)) - line+=(" ") - line=line[:-1] - line+=("\n") + line = "" + for row in pose34: + line += " ".join(str(round(i, 10)) for i in row) + line += " " + line = line[:-1] + line += "\n" fp.write(line) # fp.write('\n') fp.close() - def evaluate_pose(args): """Evaluate odometry on the KITTI dataset""" orb_pose_dir = os.path.join(args.dest, "pose") @@ -398,7 +395,6 @@ def get_error(args, filename, points, gt_filename): return err - def load_images_KITTI_VO(path_to_sequence): """Return the sequence of the images found in the path and the corrispondent timestamp @@ -454,10 +450,10 @@ def load_images_OTHERS(path_to_sequence): two array : one contains the sequence of the image filename and the second the timestamp in whitch they are acquired Inside of path_to_sequence must be: +data - xxxxxxxx.png + xxxxxxxx.png xxxxxxxy.png .... - -times.txt + -times.txt where times.txt simply contains timestamps of every frame """ @@ -469,67 +465,70 @@ def load_images_OTHERS(path_to_sequence): for line in times_file: if len(line) > 0 and not line.startswith("#"): timestamps.append(float(line)) - - for framename in sorted(os.listdir(os.path.join(path_to_sequence,"data"))): + + for framename in sorted(os.listdir(os.path.join(path_to_sequence, "data"))): if framename.endswith(".png"): framenames.append(framename) - return [os.path.join(path_to_sequence,"data",name) for name in framenames], timestamps + return [ + os.path.join(path_to_sequence, "data", name) for name in framenames + ], timestamps def load_images_TUM_VI(path_to_sequence): - """ This loader is created for Visual Inertial TUM datasets. Format of such datasets is: - path_to_sequence/mav0/cam0/+data/xxxx.png - /-times.txt + """This loader is created for Visual Inertial TUM datasets. Format of such datasets is: + path_to_sequence/mav0/cam0/+data/xxxx.png + /-times.txt """ timestamps = [] framenames = [] - - with open(os.path.join(path_to_sequence,"mav0/cam0/times.txt")) as times_file: + + with open(os.path.join(path_to_sequence, "mav0/cam0/times.txt")) as times_file: for line in times_file: if len(line) > 0 and not line.startswith("#"): framenames.append(line.split()[0] + ".png") timestamps.append(float(line.split()[1])) - - return [os.path.join(path_to_sequence,"mav0/cam0/data",name) for name in framenames], timestamps + + return [ + os.path.join(path_to_sequence, "mav0/cam0/data", name) for name in framenames + ], timestamps def load_images_EuRoC(path_to_sequence): - """ This loader is created for Visual Inertial EuRoC datasets. Format of such datasets is: - path_to_sequence/mav0/cam0/+data/xxxx.png - /-times.txt + """This loader is created for Visual Inertial EuRoC datasets. Format of such datasets is: + path_to_sequence/mav0/cam0/+data/xxxx.png + /-times.txt """ timestamps = [] framenames = [] - - with open(os.path.join(path_to_sequence,"mav0/cam0/data.csv")) as times_file: + + with open(os.path.join(path_to_sequence, "mav0/cam0/data.csv")) as times_file: for line in times_file: if len(line) > 0 and not line.startswith("#"): framenames.append(line.split(",")[1].rstrip()) - timestamps.append(float(line.split(",")[0])*1e-9) - - return [os.path.join(path_to_sequence,"mav0/cam0/data",name) for name in framenames], timestamps + timestamps.append(float(line.split(",")[0]) * 1e-9) + + return [ + os.path.join(path_to_sequence, "mav0/cam0/data", name) for name in framenames + ], timestamps def load_IMU_datas_TUM_VI(path_to_sequence): timestamp = [] gyro_data = [] acc_data = [] - with open(os.path.join(path_to_sequence,"mav0/imu0/data.csv")) as imu_file: + with open(os.path.join(path_to_sequence, "mav0/imu0/data.csv")) as imu_file: for line in imu_file: if len(line) > 0 and not line.startswith("#"): - imu_line=line.split(",") - timestamp.append(float(imu_line[0])*1e-9) - gyro_data.append([float(imu_line[1]),float(imu_line[2]),float(imu_line[3])]) - acc_data.append([float(imu_line[4]),float(imu_line[5]),float(imu_line[6])]) - - return acc_data,gyro_data,timestamp - - - - - - + imu_line = line.split(",") + timestamp.append(float(imu_line[0]) * 1e-9) + gyro_data.append( + [float(imu_line[1]), float(imu_line[2]), float(imu_line[3])] + ) + acc_data.append( + [float(imu_line[4]), float(imu_line[5]), float(imu_line[6])] + ) + return acc_data, gyro_data, timestamp