(cvimg, bbox, scale, rot, do_flip, out_shape)
| 308 | |
| 309 | |
| 310 | def generate_patch_image(cvimg, bbox, scale, rot, do_flip, out_shape): |
| 311 | img = cvimg.copy() |
| 312 | |
| 313 | img_height, img_width, img_channels = img.shape |
| 314 | |
| 315 | bb_c_x = float(bbox[0] + 0.5 * bbox[2]) |
| 316 | bb_c_y = float(bbox[1] + 0.5 * bbox[3]) |
| 317 | bb_width = float(bbox[2]) |
| 318 | bb_height = float(bbox[3]) |
| 319 | |
| 320 | if do_flip: |
| 321 | img = img[:, ::-1, :] |
| 322 | bb_c_x = img_width - bb_c_x - 1 |
| 323 | |
| 324 | trans = gen_trans_from_patch_cv(bb_c_x, bb_c_y, bb_width, bb_height, |
| 325 | out_shape[1], out_shape[0], scale, rot) |
| 326 | img_patch = cv2.warpAffine(img, |
| 327 | trans, (int(out_shape[1]), int(out_shape[0])), |
| 328 | flags=cv2.INTER_LINEAR) |
| 329 | img_patch = img_patch.astype(np.float32) |
| 330 | inv_trans = gen_trans_from_patch_cv(bb_c_x, |
| 331 | bb_c_y, |
| 332 | bb_width, |
| 333 | bb_height, |
| 334 | out_shape[1], |
| 335 | out_shape[0], |
| 336 | scale, |
| 337 | rot, |
| 338 | inv=True) |
| 339 | |
| 340 | return img_patch, trans, inv_trans |
| 341 | |
| 342 | |
| 343 | def rotate_2d(pt_2d, rot_rad): |
no test coverage detected