Reconstructs bounding boxes for multiple individuals from body part data. Parameters ---------- data : pandas.DataFrame A DataFrame containing body part data with a multi-level column index. The expected levels include: - 'individuals': Names of the individuals (
(data: pd.DataFrame, margin: float, to_xywh: bool = False)
| 101 | |
| 102 | |
| 103 | def reconstruct_all_bboxes(data: pd.DataFrame, margin: float, to_xywh: bool = False) -> NDArray: |
| 104 | """Reconstructs bounding boxes for multiple individuals from body part data. |
| 105 | |
| 106 | Parameters |
| 107 | ---------- |
| 108 | data : pandas.DataFrame |
| 109 | A DataFrame containing body part data with a multi-level column index. |
| 110 | The expected levels include: |
| 111 | - 'individuals': Names of the individuals (e.g., animals). |
| 112 | - 'x', 'y', and 'likelihood': Coordinate and confidence data for body parts. |
| 113 | margin : float |
| 114 | The margin to add/subtract from the minimum/maximum coordinates when defining the bounding box. |
| 115 | to_xywh : bool |
| 116 | If True, converts the bounding box format from [x_min, y_min, x_max, y_max] |
| 117 | to [x, y, width, height]. |
| 118 | |
| 119 | Returns |
| 120 | ------- |
| 121 | numpy.ndarray |
| 122 | A 3D array of shape (A, F, 5), where: |
| 123 | - A is the number of individuals (excluding 'single', if present). |
| 124 | - F is the number of frames (rows) in the input `data`. |
| 125 | - Each bounding box is represented as [x_min, y_min, x_max, y_max, likelihood]. |
| 126 | If `to_xywh` is True, the format will be [x, y, width, height, likelihood]. |
| 127 | |
| 128 | Notes |
| 129 | ----- |
| 130 | - Individuals are extracted from the 'individuals' level of the DataFrame columns. |
| 131 | - If an individual named 'single' exists, it is excluded from the bounding box computation. |
| 132 | - NaN values in the input data are ignored during calculations. |
| 133 | """ |
| 134 | animals = data.columns.get_level_values("individuals").unique().tolist() |
| 135 | try: |
| 136 | animals.remove("single") |
| 137 | except ValueError: |
| 138 | pass |
| 139 | bboxes = np.full((len(animals), data.shape[0], 5), np.nan) |
| 140 | for n, animal in enumerate(animals): |
| 141 | bboxes[n] = reconstruct_bboxes_from_bodyparts(data.xs(animal, axis=1, level="individuals"), margin, to_xywh) |
| 142 | return bboxes |
| 143 | |
| 144 | |
| 145 | def compute_mot_metrics( |
nothing calls this directly
no test coverage detected