Transform the bbox format from x1y1x2y2 to xywh. Args: bbox_xyxy (np.ndarray): Bounding boxes (with scores), shaped (n, 4) or (n, 5). (left, top, right, bottom, [score]) Returns: np.ndarray: Bounding boxes (with scores), shaped (n, 4) or (n, 5). (left,
(bbox_xyxy)
| 19 | |
| 20 | |
| 21 | def xyxy2xywh(bbox_xyxy): |
| 22 | """Transform the bbox format from x1y1x2y2 to xywh. |
| 23 | |
| 24 | Args: |
| 25 | bbox_xyxy (np.ndarray): Bounding boxes (with scores), shaped (n, 4) or |
| 26 | (n, 5). (left, top, right, bottom, [score]) |
| 27 | |
| 28 | Returns: |
| 29 | np.ndarray: Bounding boxes (with scores), |
| 30 | shaped (n, 4) or (n, 5). (left, top, width, height, [score]) |
| 31 | """ |
| 32 | if not isinstance(bbox_xyxy, np.ndarray): |
| 33 | raise TypeError( |
| 34 | f'Input type is {type(bbox_xyxy)}, which should be numpy.ndarray.') |
| 35 | bbox_xywh = bbox_xyxy.copy() |
| 36 | bbox_xywh[..., 2] = bbox_xywh[..., 2] - bbox_xywh[..., 0] |
| 37 | bbox_xywh[..., 3] = bbox_xywh[..., 3] - bbox_xywh[..., 1] |
| 38 | |
| 39 | return bbox_xywh |
| 40 | |
| 41 | |
| 42 | def xywh2xyxy(bbox_xywh): |
no test coverage detected