Plücker Snippet
To add camera conditioning to your policy, you can use the following minimalist snippet to get Plücker raymap from intrinsics and extrinsics. (It assumes OpenCV convention i.e. image origin at top-left, +z is forward.)
import torch
def get_plucker_raymap(K, c2w, height, width):
"""intrinsics (3,3), cam2world (4,4), height int, width int"""
vv, uu = torch.meshgrid(
torch.arange(height, device=K.device, dtype=K.dtype) + 0.5,
torch.arange(width, device=K.device, dtype=K.dtype) + 0.5,
indexing="ij",
)
rays = torch.stack([uu, vv, torch.ones_like(uu)], dim=-1)
d_world = torch.nn.functional.normalize(
(rays @ torch.linalg.inv(K).T) @ c2w[:3, :3].T,
dim=-1,
eps=1e-9,
)
o = c2w[:3, 3].view(1, 1, 3)
m = torch.cross(o, d_world, dim=-1)
return torch.cat([d_world, m], dim=-1)