MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / transform_to_camera_frame

Function transform_to_camera_frame

detrsmpl/models/body_models/utils.py:6–56  ·  view source on GitHub ↗

Transform body model parameters to camera frame. Args: global_orient (numpy.ndarray): shape (3, ). Only global_orient and transl needs to be updated in the rigid transformation transl (numpy.ndarray): shape (3, ). pelvis (numpy.ndarray): shape (3, ). 3D joint

(global_orient, transl, pelvis, extrinsic)

Source from the content-addressed store, hash-verified

4
5
6def transform_to_camera_frame(global_orient, transl, pelvis, extrinsic):
7 """Transform body model parameters to camera frame.
8
9 Args:
10 global_orient (numpy.ndarray): shape (3, ). Only global_orient and
11 transl needs to be updated in the rigid transformation
12 transl (numpy.ndarray): shape (3, ).
13 pelvis (numpy.ndarray): shape (3, ). 3D joint location of pelvis
14 This is necessary to eliminate the offset from SMPL
15 canonical space origin to pelvis, because the global orient
16 is conducted around the pelvis, not the canonical space origin
17 extrinsic (numpy.ndarray): shape (4, 4). Transformation matrix
18 from world frame to camera frame
19 Returns:
20 (new_gloabl_orient, new_transl)
21 new_gloabl_orient: transformed global orient
22 new_transl: transformed transl
23 """
24
25 # take out the small offset from smpl origin to pelvis
26 transl_offset = pelvis - transl
27 T_p2w = np.eye(4)
28 T_p2w[:3, 3] = transl_offset
29
30 # camera extrinsic: transformation from world frame to camera frame
31 T_w2c = extrinsic
32
33 # smpl transformation: from vertex frame to world frame
34 T_v2p = np.eye(4)
35 global_orient_mat = aa_to_rotmat(global_orient)
36 T_v2p[:3, :3] = global_orient_mat
37 T_v2p[:3, 3] = transl
38
39 # compute combined transformation from vertex to world
40 T_v2w = T_p2w @ T_v2p
41
42 # compute transformation from vertex to camera
43 T_v2c = T_w2c @ T_v2w
44
45 # decompose vertex to camera transformation
46 # np: new pelvis frame
47 # T_v2c = T_np2c x T_v2np
48 T_np2c = T_p2w
49 T_v2np = np.linalg.inv(T_np2c) @ T_v2c
50
51 # decompose into new global orient and new transl
52 new_global_orient_mat = T_v2np[:3, :3]
53 new_global_orient = rotmat_to_aa(new_global_orient_mat)
54 new_transl = T_v2np[:3, 3]
55
56 return new_global_orient, new_transl
57
58
59def batch_transform_to_camera_frame(global_orient, transl, pelvis, extrinsic):

Callers

nothing calls this directly

Calls 2

aa_to_rotmatFunction · 0.90
rotmat_to_aaFunction · 0.90

Tested by

no test coverage detected