-
Notifications
You must be signed in to change notification settings - Fork 339
/
Copy pathtddfa_utils.py
43 lines (34 loc) · 1.22 KB
/
tddfa_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import numpy as np
def similar_transform(pts3d, roi_box, size):
pts3d[0, :] -= 1 # for Python compatibility
pts3d[2, :] -= 1
pts3d[1, :] = size - pts3d[1, :]
sx, sy, ex, ey = roi_box
scale_x = (ex - sx) / size
scale_y = (ey - sy) / size
pts3d[0, :] = pts3d[0, :] * scale_x + sx
pts3d[1, :] = pts3d[1, :] * scale_y + sy
s = (scale_x + scale_y) / 2
pts3d[2, :] *= s
pts3d[2, :] -= np.min(pts3d[2, :])
return np.array(pts3d, dtype=np.float32)
def parse_param(param):
"""matrix pose form
param: shape=(trans_dim+shape_dim+exp_dim,), i.e., 62 = 12 + 40 + 10
"""
# pre-defined templates for parameter
n = param.shape[0]
if n == 62:
trans_dim, shape_dim, exp_dim = 12, 40, 10
elif n == 72:
trans_dim, shape_dim, exp_dim = 12, 40, 20
elif n == 141:
trans_dim, shape_dim, exp_dim = 12, 100, 29
else:
raise Exception(f'Undefined templated param parsing rule')
R_ = param[:trans_dim].reshape(3, -1)
R = R_[:, :3]
offset = R_[:, -1].reshape(3, 1)
alpha_shp = param[trans_dim:trans_dim + shape_dim].reshape(-1, 1)
alpha_exp = param[trans_dim + shape_dim:].reshape(-1, 1)
return R, offset, alpha_shp, alpha_exp