krrish94 / nerf-pytorch

A PyTorch re-implementation of Neural Radiance Fields
Other
884 stars 121 forks source link

about function get_ray_bundle #34

Open UestcJay opened 2 years ago

UestcJay commented 2 years ago

thanks for your great work! I have question about getting ray_directions. can you give me some sepcific introduction? ` ii, jj = meshgrid_xy( torch.arange( width, dtype=tform_cam2world.dtype, device=tform_cam2world.device ).to(tform_cam2world), torch.arange( height, dtype=tform_cam2world.dtype, device=tform_cam2world.device ), )

directions = torch.stack(
    [
        (ii - width * 0.5) / focal_length,
        -(jj - height * 0.5) / focal_length,
        -torch.ones_like(ii),
    ],
    dim=-1,
)
ray_directions = torch.sum(
    directions[..., None, :] * tform_cam2world[:3, :3], dim=-1
)`
cnnAndBn commented 2 years ago

@krrish94 me too, what this line for ? ray_directions = torch.sum( directions[..., None, :] * tform_cam2world[:3, :3], dim=-1 )`

daixiangzi commented 2 years ago

+1 what's different?

`def get_rays(H, W, K, R, T):

    rays_o = -np.dot(R.T, T).ravel()   
    i, j = np.meshgrid(np.arange(W, dtype=np.float32),np.arange(H, dtype=np.float32), indexing='xy')
    xy1 = np.stack([i, j, np.ones_like(i)], axis=2)
    pixel_camera = np.dot(xy1, np.linalg.inv(K).T)
    pixel_world = np.dot(pixel_camera - T.ravel(), R)
    rays_d = pixel_world - rays_o[None, None]
    rays_o = np.broadcast_to(rays_o, rays_d.shape)
    return rays_o, rays_d`