MCPcopy Create free account
hub / github.com/ModelTC/LightX2V / get_transform

Function get_transform

tools/preprocess/pose2d_utils.py:961–988  ·  view source on GitHub ↗

Generate transformation matrix.

(center, scale, res, rot=0)

Source from the content-addressed store, hash-verified

959
960
961def get_transform(center, scale, res, rot=0):
962 """Generate transformation matrix."""
963 # res: (height, width), (rows, cols)
964 crop_aspect_ratio = res[0] / float(res[1])
965 h = 200 * scale
966 w = h / crop_aspect_ratio
967 t = np.zeros((3, 3))
968 t[0, 0] = float(res[1]) / w
969 t[1, 1] = float(res[0]) / h
970 t[0, 2] = res[1] * (-float(center[0]) / w + 0.5)
971 t[1, 2] = res[0] * (-float(center[1]) / h + 0.5)
972 t[2, 2] = 1
973 if not rot == 0:
974 rot = -rot # To match direction of rotation from cropping
975 rot_mat = np.zeros((3, 3))
976 rot_rad = rot * np.pi / 180
977 sn, cs = np.sin(rot_rad), np.cos(rot_rad)
978 rot_mat[0, :2] = [cs, -sn]
979 rot_mat[1, :2] = [sn, cs]
980 rot_mat[2, 2] = 1
981 # Need to rotate around center
982 t_mat = np.eye(3)
983 t_mat[0, 2] = -res[1] / 2
984 t_mat[1, 2] = -res[0] / 2
985 t_inv = t_mat.copy()
986 t_inv[:2, 2] *= -1
987 t = np.dot(t_inv, np.dot(rot_mat, np.dot(t_mat, t)))
988 return t
989
990
991def transform(pt, center, scale, res, invert=0, rot=0):

Callers 1

transformFunction · 0.85

Calls 1

copyMethod · 0.80

Tested by

no test coverage detected