(img, crop_pos, crop_size, pad_label_value)
| 26 | |
| 27 | |
| 28 | def random_crop_pad_to_shape(img, crop_pos, crop_size, pad_label_value): |
| 29 | h, w = img.shape[:2] |
| 30 | start_crop_h, start_crop_w = crop_pos |
| 31 | assert (start_crop_h < h) and (start_crop_h >= 0) |
| 32 | assert (start_crop_w < w) and (start_crop_w >= 0) |
| 33 | |
| 34 | crop_size = get_2dshape(crop_size) |
| 35 | crop_h, crop_w = crop_size |
| 36 | |
| 37 | img_crop = img[start_crop_h : start_crop_h + crop_h, start_crop_w : start_crop_w + crop_w, ...] |
| 38 | |
| 39 | img_, margin = pad_image_to_shape(img_crop, crop_size, cv2.BORDER_CONSTANT, pad_label_value) |
| 40 | |
| 41 | return img_, margin |
| 42 | |
| 43 | |
| 44 | def generate_random_crop_pos(ori_size, crop_size): |
no test coverage detected