From 37f4e5ffdcaa759539eca8f4d2d2d4528753215f Mon Sep 17 00:00:00 2001 From: GiordanoLaminetti Date: Mon, 19 Apr 2021 00:17:48 +0200 Subject: [PATCH] format with Black --- run.py | 28 ++++++++++---------- run_MONO_IMU.py | 57 ++++++++++++++++++++--------------------- slam_method/OrbSlam3.py | 3 ++- 3 files changed, 43 insertions(+), 45 deletions(-) diff --git a/run.py b/run.py index 7df0e2b..9be2d34 100644 --- a/run.py +++ b/run.py @@ -20,11 +20,10 @@ def run(args): raise ValueError(f"Cannot find setting file at {setting_file}") if args.pose_id < -1: raise ValueError(f"Pose index must be -1 or >0") - with open(args.settings) as fs: - settings_yalm = yaml.safe_load(fs) - print("\nAlgorithm " + settings_yalm["SLAM.alg"] + " has been set\n") + settings_yalm = yaml.safe_load(fs) + print("\nAlgorithm " + settings_yalm["SLAM.alg"] + " has been set\n") print("Dataset selected: " + os.path.basename(args.dataset) + "\n") @@ -61,24 +60,24 @@ def run(args): raise ValueError(f"failed to load image {image_name}") image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) - + state = app.process_image_mono(image, timestamps[idx]) # NOTE: we buid a default invalid depth, in the case of system failure if state == slampy.State.OK: - depth = app.get_depth() + depth = app.get_depth() pose_past_frame_to_current = app.get_pose_to_target( precedent_frame=args.pose_id ) - name = os.path.splitext(os.path.basename(image_name))[0] - - depth_path = os.path.join(dest_depth, name) - save_depth(depth_path, depth) + name = os.path.splitext(os.path.basename(image_name))[0] + + depth_path = os.path.join(dest_depth, name) + save_depth(depth_path, depth) pose_path = os.path.join(dest_pose, name) save_pose(pose_path, pose_past_frame_to_current) - curr_pose = app.get_pose_to_target(-1) + curr_pose = app.get_pose_to_target(-1) if curr_pose is not None: save_pose_txt(args, name, curr_pose) @@ -89,12 +88,11 @@ def run(args): states.append(state) pbar.update(1) - - if args.is_evaluate_depth: - mean_errors = np.array(errors).mean(0) + + if args.is_evaluate_depth: + mean_errors = np.array(errors).mean(0) save_results = os.path.join(args.dest, "results.txt") save_depth_err_results(save_results, "mean values", mean_errors) - # NOTE: final dump of log.txt file with open(os.path.join(args.dest, "log.txt"), "w") as f: @@ -164,7 +162,7 @@ def run(args): type=str, help="which dataset type", default="KITTI_VO", - choices=["TUM", "KITTI_VO", "KITTI","OTHERS"], + choices=["TUM", "KITTI_VO", "KITTI", "OTHERS"], ) parser.add_argument( diff --git a/run_MONO_IMU.py b/run_MONO_IMU.py index a9e53a9..f7e5c53 100644 --- a/run_MONO_IMU.py +++ b/run_MONO_IMU.py @@ -20,11 +20,10 @@ def run(args): raise ValueError(f"Cannot find setting file at {setting_file}") if args.pose_id < -1: raise ValueError(f"Pose index must be -1 or >0") - with open(args.settings) as fs: - settings_yalm = yaml.safe_load(fs) - print("\nAlgorithm " + settings_yalm["SLAM.alg"] + " has been set\n") + settings_yalm = yaml.safe_load(fs) + print("\nAlgorithm " + settings_yalm["SLAM.alg"] + " has been set\n") print("Dataset selected: " + os.path.basename(args.dataset) + "\n") @@ -41,7 +40,7 @@ def run(args): num_images = len(image_filenames) - if args.data_type == "TUM_VI" or args.data_type =="EUROC": + if args.data_type == "TUM_VI" or args.data_type == "EUROC": acc_data, gyro_data, IMUtimestamps = load_IMU_datas_TUM_VI(args.dataset) dest_depth = os.path.join(args.dest, "depth") @@ -53,14 +52,15 @@ def run(args): states = [] errors = [] - - #finds first useful imu data, assuming imu starts recording way before camera - firstIMU=0 - while(IMUtimestamps[firstIMU]<=timestamps[0]): + # finds first useful imu data, assuming imu starts recording way before camera + firstIMU = 0 + while IMUtimestamps[firstIMU] <= timestamps[0]: firstIMU += 1 firstIMU -= 1 - - imu = [] # array of valid imu measurments: one imu measure is 7 floats [acc x, acc y, acc z, gyro x, gyro y, gyro z, timestamp] + + imu = ( + [] + ) # array of valid imu measurments: one imu measure is 7 floats [acc x, acc y, acc z, gyro x, gyro y, gyro z, timestamp] with tqdm(total=num_images) as pbar: for idx, image_name in enumerate(image_filenames): @@ -71,34 +71,34 @@ def run(args): image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) - imu.clear() #clear imu measures from last frame - - + imu.clear() # clear imu measures from last frame - if idx > 0: #select only those imu meas that occour in time before the current frame - while(IMUtimestamps[firstIMU]<=timestamps[idx]): - imu_valid_meas = (acc_data[firstIMU] + gyro_data[firstIMU]) + if ( + idx > 0 + ): # select only those imu meas that occour in time before the current frame + while IMUtimestamps[firstIMU] <= timestamps[idx]: + imu_valid_meas = acc_data[firstIMU] + gyro_data[firstIMU] imu_valid_meas.append(IMUtimestamps[firstIMU]) imu.append(imu_valid_meas) firstIMU += 1 - + state = app.process_image_imu_mono(image, timestamps[idx], np.array(imu)) # NOTE: we buid a default invalid depth, in the case of system failure if state == slampy.State.OK: - depth = app.get_depth() + depth = app.get_depth() pose_past_frame_to_current = app.get_pose_to_target( precedent_frame=args.pose_id ) - name = os.path.splitext(os.path.basename(image_name))[0] - - depth_path = os.path.join(dest_depth, name) - save_depth(depth_path, depth) + name = os.path.splitext(os.path.basename(image_name))[0] + + depth_path = os.path.join(dest_depth, name) + save_depth(depth_path, depth) pose_path = os.path.join(dest_pose, name) save_pose(pose_path, pose_past_frame_to_current) - curr_pose = app.get_pose_to_target(-1) + curr_pose = app.get_pose_to_target(-1) if curr_pose is not None: save_pose_txt(args, name, curr_pose) @@ -109,12 +109,11 @@ def run(args): states.append(state) pbar.update(1) - - if args.is_evaluate_depth: - mean_errors = np.array(errors).mean(0) + + if args.is_evaluate_depth: + mean_errors = np.array(errors).mean(0) save_results = os.path.join(args.dest, "results.txt") save_depth_err_results(save_results, "mean values", mean_errors) - # NOTE: final dump of log.txt file with open(os.path.join(args.dest, "log.txt"), "w") as f: @@ -126,7 +125,7 @@ def run(args): evaluate_pose(args) eval_tool = KittiEvalOdom() eval_tool.eval(args) - + app.shutdown() @@ -186,7 +185,7 @@ def run(args): type=str, help="which dataset type", default="KITTI_VO", - choices=["TUM", "KITTI_VO", "KITTI","OTHERS","TUM_VI","EUROC"], + choices=["TUM", "KITTI_VO", "KITTI", "OTHERS", "TUM_VI", "EUROC"], ) parser.add_argument( diff --git a/slam_method/OrbSlam3.py b/slam_method/OrbSlam3.py index e9de60f..d6b7d6e 100644 --- a/slam_method/OrbSlam3.py +++ b/slam_method/OrbSlam3.py @@ -75,7 +75,8 @@ def process_image_imu_mono(self, image, tframe, imu): def process_image_imu_stereo(self, image_left, image_right, tframe, imu): if self.sensor_type == Sensor.STEREO_IMU: self.slam.process_image_imu_stereo( - image_left, image_right, tframe, "0", imu) + image_left, image_right, tframe, "0", imu + ) else: raise Exception("The sensor type is not STREO_IMU")