in tools/camera_utils.py [0:0]
def select_cameras(cameras: CamerasBase, idx: Union[int, List[int], torch.LongTensor]):
"""
Make a new batch of cameras by indexing into the input PyTorch3D
camera batch `cameras`.
"""
if not isinstance(cameras, pt3d.renderer.PerspectiveCameras):
raise ValueError("select_cameras works only for PerspectiveCameras!")
if isinstance(idx, int):
idx = [idx]
if max(idx) >= len(cameras):
raise ValueError(f"Index {max(idx)} is out of bounds for select cameras")
cameras = pt3d.renderer.PerspectiveCameras(
**{
k: getattr(cameras, k)[idx]
for k in ("focal_length", "principal_point", "R", "T", "K")
if (hasattr(cameras, k) and (getattr(cameras, k) is not None))
},
device=cameras.device,
)
return cameras