参考https://blog.csdn.net/zhou4411781/article/details/103876478
https://www.zhihu.com/question/47760591
已知小孔成像模型如下:
简写为:
等式变型:
Nerf 取Zc=-1:
#光计算线的起点和方向向量
def get_rays(H, W, K, c2w):
i, j = torch.meshgrid(torch.linspace(0, W-1, W), torch.linspace(0, H-1, H))
i = i.t()
j = j.t()
dirs = torch.stack([(i-K[0][2])/K[0][0], -(j-K[1][2])/K[1][1], -torch.ones_like(i)], -1)
rays_d = torch.sum(dirs[..., np.newaxis, :] * c2w[:3,:3], -1)
rays_o = c2w[:3,-1].expand(rays_d.shape)
return rays_o, rays_d