Construct a camera pose homogeneous matrix H_c2w from camera frame R_w and position t_w. Args: R_w: (*, 3, 3) camera coordinate frame in the world coordinate (before flipping y-axis) t_w: (*, 3) pinhole position in the world coordinate (before flippi
(
R_w: T.Union[np.ndarray, torch.Tensor],
t_w: T.Union[np.ndarray, torch.Tensor],
invert_y: bool = True,
)
| 526 | |
| 527 | |
| 528 | def get_H_c2w_Rt( |
| 529 | R_w: T.Union[np.ndarray, torch.Tensor], |
| 530 | t_w: T.Union[np.ndarray, torch.Tensor], |
| 531 | invert_y: bool = True, |
| 532 | ) -> T.Union[np.ndarray, torch.Tensor]: |
| 533 | """ |
| 534 | Construct a camera pose homogeneous matrix H_c2w from camera frame R_w and position t_w. |
| 535 | |
| 536 | Args: |
| 537 | R_w: |
| 538 | (*, 3, 3) camera coordinate frame in the world coordinate (before flipping y-axis) |
| 539 | t_w: |
| 540 | (*, 3) pinhole position in the world coordinate (before flipping y-axis) |
| 541 | invert_y: |
| 542 | whether to invert the y axis (since image coordinate is x to right y to down) |
| 543 | |
| 544 | Returns: |
| 545 | (*, 4, 4) H_c2w |
| 546 | """ |
| 547 | |
| 548 | is_numpy = False |
| 549 | if isinstance(R_w, np.ndarray): |
| 550 | R_w = torch.from_numpy(R_w) |
| 551 | is_numpy = True |
| 552 | if isinstance(t_w, np.ndarray): |
| 553 | t_w = torch.from_numpy(t_w) |
| 554 | is_numpy = True |
| 555 | |
| 556 | # construct coordinate frame of the camera (note we flip y-axis by default) |
| 557 | if invert_y: |
| 558 | R_w[..., 1] = R_w[..., 1] * -1 |
| 559 | |
| 560 | *b_shape, _, _ = R_w |
| 561 | H_c2w = torch.zeros(*b_shape, 4, 4, device=R_w.device) |
| 562 | H_c2w[..., :3, :3] = R_w |
| 563 | H_c2w[..., :3, 3] = t_w |
| 564 | H_c2w[..., 3, 3] = 1 |
| 565 | |
| 566 | if is_numpy: |
| 567 | H_c2w = H_c2w.detach().cpu().numpy() |
| 568 | return H_c2w |
| 569 | |
| 570 | |
| 571 | def generate_random_camera_poses( |