(pose, h, w, fovy, opengl=True)
| 12 | from matplotlib import cm |
| 13 | |
| 14 | def get_rays(pose, h, w, fovy, opengl=True): |
| 15 | |
| 16 | x, y = torch.meshgrid( |
| 17 | torch.arange(w, device=pose.device), |
| 18 | torch.arange(h, device=pose.device), |
| 19 | indexing="xy", |
| 20 | ) |
| 21 | x = x.flatten() |
| 22 | y = y.flatten() |
| 23 | |
| 24 | cx = w * 0.5 |
| 25 | cy = h * 0.5 |
| 26 | |
| 27 | focal = h * 0.5 / np.tan(0.5 * np.deg2rad(fovy)) |
| 28 | |
| 29 | camera_dirs = F.pad( |
| 30 | torch.stack( |
| 31 | [ |
| 32 | (x - cx + 0.5) / focal, |
| 33 | (y - cy + 0.5) / focal * (-1.0 if opengl else 1.0), |
| 34 | ], |
| 35 | dim=-1, |
| 36 | ), |
| 37 | (0, 1), |
| 38 | value=(-1.0 if opengl else 1.0), |
| 39 | ) |
| 40 | rays_d = camera_dirs @ pose[:3, :3].transpose(0, 1) |
| 41 | rays_o = pose[:3, 3].unsqueeze(0).expand_as(rays_d) |
| 42 | |
| 43 | rays_o = rays_o.view(h, w, 3) |
| 44 | rays_d = safe_normalize(rays_d).view(h, w, 3) |
| 45 | |
| 46 | return rays_o, rays_d |
| 47 | |
| 48 | |
| 49 | def get_edge_aware_distortion_map(gt_image, distortion_map): |
no outgoing calls
no test coverage detected