Skip to content

Commit

Permalink
format with Black
Browse files Browse the repository at this point in the history
  • Loading branch information
GiordanoLaminetti committed Apr 18, 2021
1 parent ab5a673 commit 37f4e5f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 45 deletions.
28 changes: 13 additions & 15 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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)

Expand All @@ -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:
Expand Down Expand Up @@ -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(
Expand Down
57 changes: 28 additions & 29 deletions run_MONO_IMU.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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")
Expand All @@ -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):
Expand All @@ -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)

Expand All @@ -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:
Expand All @@ -126,7 +125,7 @@ def run(args):
evaluate_pose(args)
eval_tool = KittiEvalOdom()
eval_tool.eval(args)

app.shutdown()


Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion slam_method/OrbSlam3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 37f4e5f

Please sign in to comment.