MCPcopy Index your code
hub / github.com/apple/ml-pointersect / get_camera

Method get_camera

pointersect/inference/structures.py:4193–4246  ·  view source on GitHub ↗

Returns cameras in the trajactory

(
            self,
            fov: float,  # in degree
            width_px: int,
            height_px: int,
            device: torch.device = torch.device('cpu'),
    )

Source from the content-addressed store, hash-verified

4191 )
4192
4193 def get_camera(
4194 self,
4195 fov: float, # in degree
4196 width_px: int,
4197 height_px: int,
4198 device: torch.device = torch.device('cpu'),
4199 ) -> Camera:
4200 """
4201 Returns cameras in the trajactory
4202 """
4203
4204 intrinsics = render.derive_camera_intrinsics(
4205 width_px=width_px,
4206 height_px=height_px,
4207 fov=fov,
4208 dtype=self.np_dtype,
4209 ) # (3, 3) np.ndarray
4210 intrinsics = torch.from_numpy(intrinsics).to(device=device) # (3, 3)
4211
4212 if isinstance(self.cam_poses, (list, tuple)):
4213 H_c2w = []
4214 for i in range(len(self.cam_poses)):
4215 poses = [pose for pose in self.cam_poses[i]]
4216 H = torch.stack(poses, dim=0) # (n_img, 4, 4)
4217 H_c2w.append(H)
4218 H_c2w = torch.stack(H_c2w, dim=0).to(device=device) # (total, n_img, 4, 4)
4219 elif isinstance(self.cam_poses, torch.Tensor):
4220 if self.cam_poses.ndim == 3:
4221 H_c2w = self.cam_poses.unsqueeze(0) # (1, q, 4, 4)
4222 elif self.cam_poses.ndim == 2:
4223 H_c2w = self.cam_poses.view(1, 1, 4, 4) # (1, 1, 4, 4)
4224 else:
4225 assert self.cam_poses.ndim == 4
4226 H_c2w = self.cam_poses
4227 elif isinstance(self.cam_poses, np.ndarray):
4228 self.cam_poses = torch.tensor(self.cam_poses, dtype=self.torch_dtype)
4229 if self.cam_poses.ndim == 3:
4230 H_c2w = self.cam_poses.unsqueeze(0) # (1, q, 4, 4)
4231 elif self.cam_poses.ndim == 2:
4232 H_c2w = self.cam_poses.view(1, 1, 4, 4) # (1, 1, 4, 4)
4233 else:
4234 assert self.cam_poses.ndim == 4
4235 H_c2w = self.cam_poses
4236 else:
4237 raise NotImplementedError
4238
4239 *b_shape, _, _ = H_c2w.shape
4240
4241 return Camera(
4242 H_c2w=H_c2w,
4243 intrinsic=intrinsics.expand(*b_shape, 3, 3),
4244 width_px=width_px,
4245 height_px=height_px,
4246 )
4247
4248
4249class ColorCorrector(torch.nn.Module):

Callers 6

__init__Method · 0.95
render_meshFunction · 0.95
render_rgbdFunction · 0.95
render_point_cloudFunction · 0.95
sample_point_cloudMethod · 0.80

Calls 3

CameraClass · 0.85
deviceMethod · 0.80
toMethod · 0.45

Tested by

no test coverage detected