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

Function sample_regions_camera_rays_and_features

plib/utils.py:1677–1758  ·  view source on GitHub ↗

Used in PCD version of inverse rendering. Args: cam_poses: intrinsics: sample_center: region_width_px: region_height_px: features: device: Returns:

(
        cam_poses: torch.Tensor,  # (m, 4, 4) target camera pose, cam to world
        intrinsics: torch.Tensor,  # (m, 3, 3)  intrinsic matrix of the camera
        sample_center: torch.Tensor,
        region_width_px: int,
        region_height_px: int,
        features: T.Dict[str, torch.Tensor] = None,
        device=torch.device('cpu'),
)

Source from the content-addressed store, hash-verified

1675
1676
1677def sample_regions_camera_rays_and_features(
1678 cam_poses: torch.Tensor, # (m, 4, 4) target camera pose, cam to world
1679 intrinsics: torch.Tensor, # (m, 3, 3) intrinsic matrix of the camera
1680 sample_center: torch.Tensor,
1681 region_width_px: int,
1682 region_height_px: int,
1683 features: T.Dict[str, torch.Tensor] = None,
1684 device=torch.device('cpu'),
1685):
1686 """
1687 Used in PCD version of inverse rendering.
1688
1689 Args:
1690 cam_poses:
1691 intrinsics:
1692 sample_center:
1693 region_width_px:
1694 region_height_px:
1695 features:
1696 device:
1697
1698 Returns:
1699
1700 """
1701 uv_c = pinhole_projection(
1702 xyz_w=sample_center,
1703 intrinsics=intrinsics,
1704 H_c2w=cam_poses,
1705 )
1706 uv_c = torch.squeeze(uv_c) # (m, 2)
1707
1708 uv_offset = uv_c - torch.Tensor([region_width_px / 2, region_height_px / 2]).to(device=device).unsqueeze(0)
1709
1710 ray_origins_w, ray_directions_w = generate_camera_rays(
1711 cam_poses=cam_poses,
1712 intrinsics=intrinsics,
1713 width_px=region_width_px,
1714 height_px=region_height_px,
1715 subsample=1,
1716 offsets=uv_offset,
1717 device=device,
1718 ) # (b*m, h, w, 3), (b*m, h, w, 3) normalized
1719
1720 u, v = torch.meshgrid(
1721 torch.arange(0, region_width_px, 1, device=device),
1722 torch.arange(0, region_height_px, 1, device=device),
1723 indexing='xy',
1724 ) # u: (h', w') for x, v: (h', w') for y in the sensor coord
1725 u = u + 0.5
1726 v = v + 0.5
1727
1728 if features is not None:
1729 resampled_features = dict()
1730 for key in features.keys():
1731 feature = features[key]
1732 assert len(feature.shape) >= 3, "dimension of feature should contain at least n, h, w "
1733 if len(feature.shape) == 3:
1734 feature = feature.unsqueeze(-1)

Callers

nothing calls this directly

Calls 4

pinhole_projectionFunction · 0.85
generate_camera_raysFunction · 0.85
deviceMethod · 0.80
toMethod · 0.45

Tested by

no test coverage detected