Skip to content

Commit

Permalink
Create depth warper notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
Mona Fathollahi committed Oct 1, 2018
1 parent 9d24778 commit 3c96835
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 39 deletions.
178 changes: 154 additions & 24 deletions examples/depth_warper/Depth_warper.ipynb

Large diffs are not rendered by default.

14 changes: 0 additions & 14 deletions examples/depth_warper/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,6 @@ def load_depth(file_name):
return torch.from_numpy(depth).view(1, 1, *depth.shape).float()


def create_pinhole(intrinsic, extrinsic, height, width):
pinhole = torch.zeros(12)
pinhole[0] = intrinsic[0, 0] # fx
pinhole[1] = intrinsic[1, 1] # fy
pinhole[2] = intrinsic[0, 2] # cx
pinhole[3] = intrinsic[1, 2] # cy
pinhole[4] = height
pinhole[5] = width
pinhole[6:9] = dgm.transforms.rotation_matrix_to_angle_axis(
torch.tensor(extrinsic))
pinhole[9:12] = torch.tensor(extrinsic[:, 3])
return pinhole.view(1, -1)


def load_camera_data(file_name):
"""Loads the camera data using the syntel SDK and converts to torch.Tensor.
"""
Expand Down
18 changes: 17 additions & 1 deletion torchgeometry/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
__all__ = [
"tensor_to_image",
"image_to_tensor",
"draw_rectangle"
"draw_rectangle",
"create_pinhole"
]


Expand All @@ -30,6 +31,21 @@ def tensor_to_image(tensor):
tensor = torch.unsqueeze(tensor, dim=0)
return tensor.permute(1, 2, 0).contiguous().cpu().detach().numpy()


def create_pinhole(intrinsic, extrinsic, height, width):
pinhole = torch.zeros(12)
pinhole[0] = intrinsic[0, 0] # fx
pinhole[1] = intrinsic[1, 1] # fy
pinhole[2] = intrinsic[0, 2] # cx
pinhole[3] = intrinsic[1, 2] # cy
pinhole[4] = height
pinhole[5] = width
pinhole[6:9] = tgm.rotation_matrix_to_angle_axis(
torch.tensor(extrinsic))
pinhole[9:12] = torch.tensor(extrinsic[:, 3])
return pinhole.view(1, -1)


def draw_rectangle(image, dst_homo_src):
height, width = image.shape[:2]
pts_src = torch.FloatTensor([[
Expand Down

0 comments on commit 3c96835

Please sign in to comment.