in dataset/co3d_dataset.py [0:0]
def _get_pytorch3d_camera(self, entry, scale, clamp_bbox_xyxy):
# principal point and focal length
principal_point = torch.tensor(
entry.viewpoint.principal_point, dtype=torch.float
)
focal_length = torch.tensor(
entry.viewpoint.focal_length, dtype=torch.float
)
# first, we convert from the legacy Pytorch3D NDC convention
# (currently used in CO3D for storing intrinsics) to pixels
half_image_size_wh_orig = (
torch.tensor(list(reversed(entry.image.size)), dtype=torch.float)
/ 2.0
)
# principal point and focal length in pixels
principal_point_px = (
-1.0 * (principal_point - 1.0) * half_image_size_wh_orig
)
focal_length_px = focal_length * half_image_size_wh_orig
if self.box_crop:
assert clamp_bbox_xyxy is not None
principal_point_px -= clamp_bbox_xyxy[:2]
# now, convert from pixels to Pytorch3D v0.5+ NDC convention
if self.image_height is None or self.image_width is None:
out_size = list(reversed(entry.image.size))
else:
out_size = [self.image_width, self.image_height]
half_image_size_output = torch.tensor(out_size, dtype=torch.float) / 2.0
half_min_image_size_output = half_image_size_output.min()
# rescaled principal point and focal length in ndc
principal_point = (
half_image_size_output - principal_point_px * scale
) / half_min_image_size_output
focal_length = focal_length_px * scale / half_min_image_size_output
return PerspectiveCameras(
focal_length=focal_length[None],
principal_point=principal_point[None],
R=torch.tensor(entry.viewpoint.R, dtype=torch.float)[None],
T=torch.tensor(entry.viewpoint.T, dtype=torch.float)[None],
)