(self, results)
| 926 | self.crop_with_bbox = crop_with_bbox |
| 927 | |
| 928 | def __call__(self, results): |
| 929 | |
| 930 | c = results['center'] |
| 931 | s = results['scale'] |
| 932 | r = results['rotation'] |
| 933 | |
| 934 | trans = get_affine_transform(c, s, r, self.image_size) |
| 935 | |
| 936 | if 'img' in results: |
| 937 | img = results['img'].copy() |
| 938 | |
| 939 | # img before affine |
| 940 | ori_img = img.copy() |
| 941 | results['crop_transform'] = trans |
| 942 | results['ori_img'] = ori_img |
| 943 | results['img_fields'] = ['img', 'ori_img'] |
| 944 | |
| 945 | img = cv2.warpAffine( |
| 946 | img, |
| 947 | trans, (int(self.image_size[0]), int(self.image_size[1])), |
| 948 | flags=cv2.INTER_LINEAR) |
| 949 | results['img'] = img |
| 950 | |
| 951 | if 'keypoints2d' in results: |
| 952 | keypoints2d = results['keypoints2d'].copy() |
| 953 | |
| 954 | results['keypoints2d'][..., :2] = affine_transform( |
| 955 | keypoints2d, trans) |
| 956 | if 'bbox_xywh' in results: |
| 957 | bbox_xywh = results['bbox_xywh'].copy() |
| 958 | |
| 959 | leftTop = bbox_xywh[..., :2] |
| 960 | rightTop = np.concatenate([ |
| 961 | bbox_xywh[..., [0]] + bbox_xywh[..., [2]], bbox_xywh[..., [1]] |
| 962 | ], -1) |
| 963 | leftBottom = np.concatenate([ |
| 964 | bbox_xywh[..., [0]], bbox_xywh[..., [1]] + bbox_xywh[..., [3]] |
| 965 | ], -1) |
| 966 | rightBottom = np.concatenate([ |
| 967 | bbox_xywh[..., [0]] + bbox_xywh[..., [2]], |
| 968 | bbox_xywh[..., [1]] + bbox_xywh[..., [3]] |
| 969 | ], -1) |
| 970 | |
| 971 | bbox_point = np.vstack( |
| 972 | [leftTop, rightTop, leftBottom, rightBottom]) |
| 973 | bbox_point = np.concatenate( |
| 974 | [bbox_point, np.ones_like(bbox_point[..., [0]])], -1) |
| 975 | bbox_point = affine_transform(bbox_point, trans) |
| 976 | # TODO: |
| 977 | bbox_point = np.clip(bbox_point, 0, self.img_res) |
| 978 | bbox__xywh_t = bbox_point.clone() |
| 979 | bbox__xywh_t |
| 980 | results['bbox'] = bbox_point |
| 981 | |
| 982 | # bbox_xyxy = xywh2xyxy(bbox_xywh)[:,:4].reshape(-1, 2, 2) |
| 983 | # bbox_xyxy = np.concatenate([bbox_xyxy, np.ones_like(bbox_xyxy[...,[0]])], -1) |
| 984 | # bbox_xyxy = np.concatenate([affine_transform(bbox_xyxy, trans).reshape(-1,4), bbox_xywh[...,[-1]]],-1) |
| 985 | # results['bbox_xywh'] = xyxy2xywh(bbox_xyxy) |
nothing calls this directly
no test coverage detected