MCPcopy
hub / github.com/xingyizhou/CenterNet / get_affine_transform

Function get_affine_transform

src/lib/utils/image.py:27–60  ·  view source on GitHub ↗
(center,
                         scale,
                         rot,
                         output_size,
                         shift=np.array([0, 0], dtype=np.float32),
                         inv=0)

Source from the content-addressed store, hash-verified

25
26
27def get_affine_transform(center,
28 scale,
29 rot,
30 output_size,
31 shift=np.array([0, 0], dtype=np.float32),
32 inv=0):
33 if not isinstance(scale, np.ndarray) and not isinstance(scale, list):
34 scale = np.array([scale, scale], dtype=np.float32)
35
36 scale_tmp = scale
37 src_w = scale_tmp[0]
38 dst_w = output_size[0]
39 dst_h = output_size[1]
40
41 rot_rad = np.pi * rot / 180
42 src_dir = get_dir([0, src_w * -0.5], rot_rad)
43 dst_dir = np.array([0, dst_w * -0.5], np.float32)
44
45 src = np.zeros((3, 2), dtype=np.float32)
46 dst = np.zeros((3, 2), dtype=np.float32)
47 src[0, :] = center + scale_tmp * shift
48 src[1, :] = center + src_dir + scale_tmp * shift
49 dst[0, :] = [dst_w * 0.5, dst_h * 0.5]
50 dst[1, :] = np.array([dst_w * 0.5, dst_h * 0.5], np.float32) + dst_dir
51
52 src[2:, :] = get_3rd_point(src[0, :], src[1, :])
53 dst[2:, :] = get_3rd_point(dst[0, :], dst[1, :])
54
55 if inv:
56 trans = cv2.getAffineTransform(np.float32(dst), np.float32(src))
57 else:
58 trans = cv2.getAffineTransform(np.float32(src), np.float32(dst))
59
60 return trans
61
62
63def affine_transform(pt, t):

Callers 8

pre_processMethod · 0.90
pre_processMethod · 0.90
__getitem__Method · 0.90
__getitem__Method · 0.90
__getitem__Method · 0.90
__getitem__Method · 0.90
transform_predsFunction · 0.85
cropFunction · 0.85

Calls 2

get_dirFunction · 0.85
get_3rd_pointFunction · 0.85

Tested by

no test coverage detected