Get scaled bounding box from keypoints 2D.
(points, bbox_scale_factor: float = 1.0)
| 117 | |
| 118 | |
| 119 | def points_to_bbox(points, bbox_scale_factor: float = 1.0): |
| 120 | """Get scaled bounding box from keypoints 2D.""" |
| 121 | min_coords, _ = torch.min(points, dim=1) |
| 122 | xmin, ymin = min_coords[:, 0], min_coords[:, 1] |
| 123 | max_coords, _ = torch.max(points, dim=1) |
| 124 | xmax, ymax = max_coords[:, 0], max_coords[:, 1] |
| 125 | |
| 126 | center = torch.stack([xmax + xmin, ymax + ymin], dim=-1) * 0.5 |
| 127 | |
| 128 | width = (xmax - xmin) |
| 129 | height = (ymax - ymin) |
| 130 | |
| 131 | # Convert the bounding box to a square box |
| 132 | size = torch.max(width, height) * bbox_scale_factor |
| 133 | |
| 134 | return center, size |
| 135 | |
| 136 | |
| 137 | def get_crop_info(points, |