| 172 | |
| 173 | |
| 174 | def crop_keypoints(kp, name, data_dir, box_postfix): |
| 175 | kp = kp.copy() |
| 176 | |
| 177 | # load our bbox |
| 178 | box_path = Path(data_dir) / (name + box_postfix) |
| 179 | # id, xmin, ymin, w, h, full w, full h, sharpness |
| 180 | box_xmin, box_ymin, box_w, box_h = np.loadtxt(box_path)[1:5] |
| 181 | |
| 182 | # crop the original keypoints |
| 183 | kp[:, 0] -= box_xmin |
| 184 | kp[:, 1] -= box_ymin |
| 185 | # scale keypoints to [-1, 1] |
| 186 | kp[:, 0] = kp[:, 0] / box_w * 2 - 1 |
| 187 | kp[:, 1] = kp[:, 1] / box_h * 2 - 1 |
| 188 | |
| 189 | return kp |
| 190 | |
| 191 | |
| 192 | def crop_keypoints_with_box(kp, box): |