MCPcopy Create free account
hub / github.com/YuxuanSnow/Human3Diffusion / get_rays

Function get_rays

core/utils.py:14–46  ·  view source on GitHub ↗
(pose, h, w, fovy, opengl=True)

Source from the content-addressed store, hash-verified

12from matplotlib import cm
13
14def 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
49def get_edge_aware_distortion_map(gt_image, distortion_map):

Callers 4

__getitem__Method · 0.90
prepare_default_raysMethod · 0.90
__getitem__Method · 0.90
prepare_default_raysMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected