Uniformly enlarge bbox(es) by the given factors.
(
annotation_position: Union[List[float], List[List[float]]],
width_factor: float = 1.2,
height_factor: float = 1.2,
)
| 28 | |
| 29 | |
| 30 | def _resize_annotation_bounding_boxes( |
| 31 | annotation_position: Union[List[float], List[List[float]]], |
| 32 | width_factor: float = 1.2, |
| 33 | height_factor: float = 1.2, |
| 34 | ): |
| 35 | """Uniformly enlarge bbox(es) by the given factors.""" |
| 36 | |
| 37 | def _resize(box: List[float]): |
| 38 | y, x, h, w = box |
| 39 | h_delta = (height_factor - 1) * h |
| 40 | w_delta = (width_factor - 1) * w |
| 41 | y = max(0, y - h_delta / 2) |
| 42 | x = max(0, x - w_delta / 2) |
| 43 | h = min(1, h + h_delta) |
| 44 | w = min(1, w + w_delta) |
| 45 | return [y, x, h, w] |
| 46 | |
| 47 | if not annotation_position: |
| 48 | return [] |
| 49 | if isinstance(annotation_position[0], list): |
| 50 | return [_resize(b) for b in annotation_position] |
| 51 | return _resize(annotation_position) |
| 52 | |
| 53 | |
| 54 | def is_tap_action(normalized_start_yx, normalized_end_yx): |