Skip to content

Commit

Permalink
fixed error in dump pose
Browse files Browse the repository at this point in the history
  • Loading branch information
FilippoAleotti committed Nov 21, 2020
1 parent c50d4e1 commit 219497b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ def run(args):
# NOTE: we buid a default invalid depth, in the case of system failure
h, w = image.shape[:2]
depth = np.full((h, w), -1, dtype=np.float32)
pose_past_frame_to_current = np.full((4, 4), -1, dtype=np.float32)
if state == slampy.State.OK:
depth = app.get_depth()

pose_past_frame_to_current = app.get_pose(precedent_frame=args.pose_id)
states.append(state)

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)
pose_past_frame_to_current = app.get_pose(precedent_frame=args.pose_id)
save_pose(pose_path, pose_past_frame_to_current)

pbar.update(1)
Expand Down
17 changes: 11 additions & 6 deletions slampy.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def process_image_rgbd(self, image, tframe):
tframe (float): the timestamp when the image was capture
Returns:
the state of the traking in this frame
the new state of the SLAM system
Raises:
Exception: if the sensor type is different from RGBD
Expand All @@ -176,6 +176,7 @@ def get_pose(self, precedent_frame=-1):
Returns:
the 4x4 pose matrix corresponding to the transormation between the precedent_frame and the current one.
If the state is not State.OK, return None
Examples:
Expand All @@ -195,6 +196,7 @@ def get_pose(self, precedent_frame=-1):
self.slam.get_pose(),
np.linalg.inv(self.pose_array[-precedent_frame]),
)
return None

def get_abs_cloud(self):
"""Get the point cloud at the current frame stored in it's aboslute coordinate .
Expand All @@ -205,6 +207,7 @@ def get_abs_cloud(self):
"""
if self.get_state() == State.OK:
return self.slam.get_abs_cloud()
return None

def get_point_cloud(self):
"""Get the point cloud at the current frame form the wiev of the current position .
Expand All @@ -215,6 +218,7 @@ def get_point_cloud(self):
"""
if self.get_state() == State.OK:
return [cp for (cp, _) in self._get_2d_point()]
return None

def get_depth(self):
"""Get the depth computed in the current image.
Expand All @@ -223,17 +227,18 @@ def get_depth(self):
an array of the image shape with depth when it is aviable otherwise -1 , None if the traking is failed
"""
depth = None
if self.get_state() == State.OK:
depth = np.ones(self.image_shape[0:2]) * -1
for (cp, point) in self._get_2d_point():
depth[point[1], point[0]] = cp[2]
return depth
return depth

def _get_2d_point(self):
"""This private method is used to compute the transormation between the absolute point to the image point
Return:
an array of pair (camera view, image point) , None if the traking is failed
an array of pair (camera view, image point) , an empty list if the traking is failed
"""
points2D = []
Expand All @@ -258,17 +263,17 @@ def _get_2d_point(self):
return points2D

def get_state(self):
"""Return the state of the SLAM tracking in the last frame
"""Get the current state of the SLAM system
Returns:
an State enums corresponding to the state
"""
return self.slam.get_state()

def shutdown(self):
"""Shutdown the SLAM algorithm"""
"""Shutdown the SLAM system"""
self.slam.shutdown()

def reset(self):
"""Reset SLAM algorithm"""
"""Reset SLAM system"""
self.slam.reset()

0 comments on commit 219497b

Please sign in to comment.