保持检测框中心点位置不变调整检测框比例为cfg.input_img_size ration: 扩大检测框大小
(bbox, img_width, img_height, ratio=1.25)
| 59 | |
| 60 | |
| 61 | def process_bbox(bbox, img_width, img_height, ratio=1.25): |
| 62 | ''' |
| 63 | 保持检测框中心点位置不变调整检测框比例为cfg.input_img_size |
| 64 | |
| 65 | ration: 扩大检测框大小''' |
| 66 | bbox = sanitize_bbox(bbox, img_width, img_height) |
| 67 | if bbox is None: |
| 68 | return bbox |
| 69 | |
| 70 | # aspect ratio preserving bbox |
| 71 | w = bbox[2] |
| 72 | h = bbox[3] |
| 73 | c_x = bbox[0] + w / 2. |
| 74 | c_y = bbox[1] + h / 2. |
| 75 | aspect_ratio = cfg.input_img_shape[1] / cfg.input_img_shape[0] |
| 76 | if w > aspect_ratio * h: |
| 77 | h = w / aspect_ratio |
| 78 | elif w < aspect_ratio * h: |
| 79 | w = h * aspect_ratio |
| 80 | bbox[2] = w * ratio |
| 81 | bbox[3] = h * ratio |
| 82 | bbox[0] = c_x - bbox[2] / 2. |
| 83 | bbox[1] = c_y - bbox[3] / 2. |
| 84 | |
| 85 | bbox = bbox.astype(np.float32) |
| 86 | return bbox |
| 87 | |
| 88 | |
| 89 | def get_aug_config(): |