MCPcopy Create free account
hub / github.com/apple/ml-pointersect / get_H_c2w_Rt

Function get_H_c2w_Rt

plib/rigid_motion.py:528–568  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

526
527
528def 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
571def generate_random_camera_poses(

Callers

nothing calls this directly

Calls 1

detachMethod · 0.45

Tested by

no test coverage detected