MCPcopy Create free account
hub / github.com/Francis-Rings/FlashPortrait / ray_condition

Function ray_condition

wan/data/utils.py:244–277  ·  view source on GitHub ↗

Copied from https://github.com/hehao13/CameraCtrl/blob/main/inference.py

(K, c2w, H, W, device)

Source from the content-addressed store, hash-verified

242 return ret_poses
243
244def ray_condition(K, c2w, H, W, device):
245 """Copied from https://github.com/hehao13/CameraCtrl/blob/main/inference.py
246 """
247 # c2w: B, V, 4, 4
248 # K: B, V, 4
249
250 B = K.shape[0]
251
252 j, i = custom_meshgrid(
253 torch.linspace(0, H - 1, H, device=device, dtype=c2w.dtype),
254 torch.linspace(0, W - 1, W, device=device, dtype=c2w.dtype),
255 )
256 i = i.reshape([1, 1, H * W]).expand([B, 1, H * W]) + 0.5 # [B, HxW]
257 j = j.reshape([1, 1, H * W]).expand([B, 1, H * W]) + 0.5 # [B, HxW]
258
259 fx, fy, cx, cy = K.chunk(4, dim=-1) # B,V, 1
260
261 zs = torch.ones_like(i) # [B, HxW]
262 xs = (i - cx) / fx * zs
263 ys = (j - cy) / fy * zs
264 zs = zs.expand_as(ys)
265
266 directions = torch.stack((xs, ys, zs), dim=-1) # B, V, HW, 3
267 directions = directions / directions.norm(dim=-1, keepdim=True) # B, V, HW, 3
268
269 rays_d = directions @ c2w[..., :3, :3].transpose(-1, -2) # B, V, 3, HW
270 rays_o = c2w[..., :3, 3] # B, V, 3
271 rays_o = rays_o[:, :, None].expand_as(rays_d) # B, V, 3, HW
272 # c2w @ dirctions
273 rays_dxo = torch.cross(rays_o, rays_d)
274 plucker = torch.cat([rays_dxo, rays_d], dim=-1)
275 plucker = plucker.reshape(B, c2w.shape[1], H, W, 6) # B, V, H, W, 6
276 # plucker = plucker.permute(0, 1, 4, 2, 3)
277 return plucker
278
279def process_pose_file(pose_file_path, width=672, height=384, original_pose_width=1280, original_pose_height=720, device='cpu', return_poses=False):
280 """Modified from https://github.com/hehao13/CameraCtrl/blob/main/inference.py

Callers 2

process_pose_fileFunction · 0.85
process_pose_paramsFunction · 0.85

Calls 1

custom_meshgridFunction · 0.85

Tested by

no test coverage detected