(self, bbox, do_flip, img_shape, img2bb_trans,
input_img_shape)
| 912 | return result |
| 913 | |
| 914 | def process_hand_face_bbox(self, bbox, do_flip, img_shape, img2bb_trans, |
| 915 | input_img_shape): |
| 916 | if bbox is None: |
| 917 | bbox = np.array([0, 0, 1, 1], |
| 918 | dtype=np.float32).reshape(2, 2) # dummy value |
| 919 | bbox_valid = float(False) # dummy value |
| 920 | else: |
| 921 | # reshape to top-left (x,y) and bottom-right (x,y) |
| 922 | bbox = bbox.reshape(2, 2) |
| 923 | |
| 924 | # flip augmentation |
| 925 | if do_flip: |
| 926 | bbox[:, 0] = img_shape[1] - bbox[:, 0] - 1 |
| 927 | bbox[0, 0], bbox[1, 0] = bbox[1, 0].copy(), bbox[ |
| 928 | 0, 0].copy() # xmin <-> xmax swap |
| 929 | |
| 930 | # make four points of the bbox |
| 931 | bbox = bbox.reshape(4).tolist() |
| 932 | xmin, ymin, xmax, ymax = bbox |
| 933 | bbox = np.array( |
| 934 | [[xmin, ymin], [xmax, ymin], [xmax, ymax], [xmin, ymax]], |
| 935 | dtype=np.float32).reshape(4, 2) |
| 936 | |
| 937 | # affine transformation (crop, rotation, scale) |
| 938 | bbox_xy1 = np.concatenate((bbox, np.ones_like(bbox[:, :1])), 1) |
| 939 | bbox = np.dot(img2bb_trans, |
| 940 | bbox_xy1.transpose(1, 0)).transpose(1, 0)[:, :2] |
| 941 | |
| 942 | # print(bbox) |
| 943 | # bbox[:, 0] = bbox[:, 0] / input_img_shape[1] * cfg.output_hm_shape[2] |
| 944 | # bbox[:, 1] = bbox[:, 1] / input_img_shape[0] * cfg.output_hm_shape[1] |
| 945 | bbox[:, 0] /= input_img_shape[1] |
| 946 | bbox[:, 1] /= input_img_shape[0] |
| 947 | |
| 948 | |
| 949 | # make box a rectangle without rotation |
| 950 | if np.max(bbox[:,0])<=0 or np.min(bbox[:,0])>=1 or np.max(bbox[:,1])<=0 or np.min(bbox[:,1])>=1: |
| 951 | bbox_valid = float(False) |
| 952 | bbox = np.array([0, 0, 1, 1], dtype=np.float32) |
| 953 | else: |
| 954 | xmin = np.max([np.min(bbox[:, 0]), 0]) |
| 955 | xmax = np.min([np.max(bbox[:, 0]), 1]) |
| 956 | ymin = np.max([np.min(bbox[:, 1]), 0]) |
| 957 | ymax = np.min([np.max(bbox[:, 1]), 1]) |
| 958 | bbox = np.array([xmin, ymin, xmax, ymax], dtype=np.float32) |
| 959 | |
| 960 | bbox = np.clip(bbox,0,1) |
| 961 | bbox_valid = float(True) |
| 962 | bbox = bbox.reshape(2, 2) |
| 963 | |
| 964 | return bbox, bbox_valid |
| 965 | |
| 966 | def evaluate(self, outs, cur_sample_idx=None): |
| 967 | annots = self.datalist |
no test coverage detected