MCPcopy Create free account
hub / github.com/MotrixLab/ViMoGen / get_R_T

Function get_R_T

motion_rep/motion_checker.py:62–98  ·  view source on GitHub ↗

Compute simple camera rotation/translation from joints.

(
    joints: torch.Tensor, set_center: bool = True, zero_trans: bool = False, identity_R: bool = False
)

Source from the content-addressed store, hash-verified

60
61
62def get_R_T(
63 joints: torch.Tensor, set_center: bool = True, zero_trans: bool = False, identity_R: bool = False
64) -> Tuple[torch.Tensor, torch.Tensor]:
65 """Compute simple camera rotation/translation from joints."""
66 seq_len = joints.shape[0]
67 roots = joints[:, 0]
68 xyz_move = roots.amax(dim=0) - roots.amin(dim=0)
69 y_max = roots.amax(dim=0)[1]
70 z_max = roots.amax(dim=0)[2]
71 x_move = xyz_move[0]
72 y_move = xyz_move[1]
73 z_move = xyz_move[2]
74 if identity_R:
75 R = torch.tensor(
76 [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, -1.0]],
77 dtype=torch.float32,
78 device=joints.device,
79 )
80 depth_offset = 2.5 + 1.0 * x_move + 2.0 * y_move + z_max
81 T = torch.tensor([0.0, 0.0, 1.0], dtype=torch.float32, device=joints.device) * depth_offset
82 if set_center:
83 T[1] = -roots[0, 1]
84 else:
85 R = torch.tensor(
86 [[1.0, 0.0, 0.0], [0.0, 0.0, -1.0], [0.0, 1.0, 0.0]],
87 dtype=torch.float32,
88 device=joints.device,
89 )
90 depth_offset = 2.5 + 1.0 * x_move + 2.0 * z_move + y_max
91 T = torch.tensor([0.0, 0.0, 1.0], dtype=torch.float32, device=joints.device) * depth_offset
92 if set_center:
93 T[1] = -roots[0, 2]
94
95 if zero_trans:
96 T = torch.zeros_like(T)
97 R, T = R[None, :].repeat(seq_len, 1, 1), T[None].repeat(seq_len, 1)
98 return R, T
99
100
101def estimate_focal_length(img_w: int, img_h: int, fov: float = 55) -> float:

Callers 1

motion_visFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected