(center,
scale,
rot,
output_size,
shift=np.array([0, 0], dtype=np.float32),
inv=0,
pixel_std=200)
| 23 | |
| 24 | |
| 25 | def get_affine_transform(center, |
| 26 | scale, |
| 27 | rot, |
| 28 | output_size, |
| 29 | shift=np.array([0, 0], dtype=np.float32), |
| 30 | inv=0, |
| 31 | pixel_std=200): |
| 32 | if not isinstance(scale, np.ndarray) and not isinstance(scale, list): |
| 33 | print(scale) |
| 34 | scale = np.array([scale, scale]) |
| 35 | |
| 36 | scale_tmp = scale * pixel_std |
| 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 | |
| 43 | src_dir = get_dir([0, (src_w-1) * -0.5], rot_rad) |
| 44 | dst_dir = np.array([0, (dst_w-1) * -0.5], np.float32) |
| 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-1) * 0.5, (dst_h-1) * 0.5] |
| 50 | dst[1, :] = np.array([(dst_w-1) * 0.5, (dst_h-1) * 0.5]) + 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 | |
| 63 | def affine_transform(pt, t): |
no test coverage detected