| 8 | |
| 9 | |
| 10 | class RGBDFrame(nn.Module): |
| 11 | def __init__(self, fid, rgb, depth, K, offset, ref_pose=None) -> None: |
| 12 | super().__init__() |
| 13 | self.stamp = fid |
| 14 | self.h, self.w = depth.shape |
| 15 | if type(rgb) != torch.Tensor: |
| 16 | rgb = torch.FloatTensor(rgb).cuda() |
| 17 | if type(depth) != torch.Tensor: |
| 18 | depth = torch.FloatTensor(depth).cuda() # / 2 |
| 19 | self.rgb = rgb.cuda() |
| 20 | self.depth = depth.cuda() |
| 21 | self.K = K |
| 22 | |
| 23 | if ref_pose is not None: |
| 24 | if len(ref_pose.shape) != 2: |
| 25 | ref_pose = ref_pose.reshape(4, 4) |
| 26 | if type(ref_pose) != torch.Tensor: # from gt data |
| 27 | self.ref_pose = torch.tensor(ref_pose, requires_grad=False, dtype=torch.float32) |
| 28 | self.ref_pose[:3, 3] += offset # Offset ensures voxel coordinates>0 |
| 29 | else: # from tracked data |
| 30 | self.ref_pose = ref_pose.clone().requires_grad_(False) |
| 31 | self.d_pose = OptimizablePose.from_matrix(torch.eye(4, requires_grad=False, dtype=torch.float32)) |
| 32 | else: |
| 33 | self.ref_pose = None |
| 34 | self.precompute() |
| 35 | |
| 36 | def get_d_pose(self): |
| 37 | return self.d_pose.matrix() |
| 38 | |
| 39 | def get_d_translation(self): |
| 40 | return self.d_pose.translation() |
| 41 | |
| 42 | def get_d_rotation(self): |
| 43 | return self.d_pose.rotation() |
| 44 | |
| 45 | def get_d_pose_param(self): |
| 46 | return self.d_pose.parameters() |
| 47 | |
| 48 | def get_ref_pose(self): |
| 49 | return self.ref_pose |
| 50 | |
| 51 | def get_ref_translation(self): |
| 52 | return self.ref_pose[:3, 3] |
| 53 | |
| 54 | def get_ref_rotation(self): |
| 55 | return self.ref_pose[:3, :3] |
| 56 | |
| 57 | @torch.no_grad() |
| 58 | def get_rays(self, w=None, h=None, K=None): |
| 59 | w = self.w if w == None else w |
| 60 | h = self.h if h == None else h |
| 61 | if K is None: |
| 62 | K = np.eye(3) |
| 63 | K[0, 0] = self.K[0, 0] * w / self.w |
| 64 | K[1, 1] = self.K[1, 1] * h / self.h |
| 65 | K[0, 2] = self.K[0, 2] * w / self.w |
| 66 | K[1, 2] = self.K[1, 2] * h / self.h |
| 67 | ix, iy = torch.meshgrid( |
no outgoing calls
no test coverage detected