Modified from https://github.com/hehao13/CameraCtrl/blob/main/inference.py
(pose_file_path, width=672, height=384, original_pose_width=1280, original_pose_height=720, device='cpu', return_poses=False)
| 277 | return plucker |
| 278 | |
| 279 | def 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 |
| 281 | """ |
| 282 | with open(pose_file_path, 'r') as f: |
| 283 | poses = f.readlines() |
| 284 | |
| 285 | poses = [pose.strip().split(' ') for pose in poses[1:]] |
| 286 | cam_params = [[float(x) for x in pose] for pose in poses] |
| 287 | if return_poses: |
| 288 | return cam_params |
| 289 | else: |
| 290 | cam_params = [Camera(cam_param) for cam_param in cam_params] |
| 291 | |
| 292 | sample_wh_ratio = width / height |
| 293 | pose_wh_ratio = original_pose_width / original_pose_height # Assuming placeholder ratios, change as needed |
| 294 | |
| 295 | if pose_wh_ratio > sample_wh_ratio: |
| 296 | resized_ori_w = height * pose_wh_ratio |
| 297 | for cam_param in cam_params: |
| 298 | cam_param.fx = resized_ori_w * cam_param.fx / width |
| 299 | else: |
| 300 | resized_ori_h = width / pose_wh_ratio |
| 301 | for cam_param in cam_params: |
| 302 | cam_param.fy = resized_ori_h * cam_param.fy / height |
| 303 | |
| 304 | intrinsic = np.asarray([[cam_param.fx * width, |
| 305 | cam_param.fy * height, |
| 306 | cam_param.cx * width, |
| 307 | cam_param.cy * height] |
| 308 | for cam_param in cam_params], dtype=np.float32) |
| 309 | |
| 310 | K = torch.as_tensor(intrinsic)[None] # [1, 1, 4] |
| 311 | c2ws = get_relative_pose(cam_params) # Assuming this function is defined elsewhere |
| 312 | c2ws = torch.as_tensor(c2ws)[None] # [1, n_frame, 4, 4] |
| 313 | plucker_embedding = ray_condition(K, c2ws, height, width, device=device)[0].permute(0, 3, 1, 2).contiguous() # V, 6, H, W |
| 314 | plucker_embedding = plucker_embedding[None] |
| 315 | plucker_embedding = rearrange(plucker_embedding, "b f c h w -> b f h w c")[0] |
| 316 | return plucker_embedding |
| 317 | |
| 318 | def process_pose_params(cam_params, width=672, height=384, original_pose_width=1280, original_pose_height=720, device='cpu'): |
| 319 | """Modified from https://github.com/hehao13/CameraCtrl/blob/main/inference.py |
nothing calls this directly
no test coverage detected