Utils
generate_2d_mask¶
Generate a 2D mask from a polygon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
polygon |
ndarray
|
The polygon for which the mask should be generated, given as a list of vertices. |
required |
resolution_wh |
Tuple[int, int]
|
The width and height of the desired resolution. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The generated 2D mask, where the polygon is marked with |
Source code in supervision/detection/utils.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
box_iou_batch¶
Compute Intersection over Union (IoU) of two sets of bounding boxes - boxes_true and boxes_detection. Both sets
of boxes are expected to be in (x_min, y_min, x_max, y_max) format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boxes_true |
ndarray
|
2D |
required |
boxes_detection |
ndarray
|
2D |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Pairwise IoU of boxes from |
Source code in supervision/detection/utils.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
non_max_suppression¶
Perform Non-Maximum Suppression (NMS) on object detection predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions |
ndarray
|
An array of object detection predictions in the format of |
required |
iou_threshold |
float
|
The intersection-over-union threshold to use for non-maximum suppression. |
0.5
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: A boolean array indicating which predictions to keep after non-maximum suppression. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If |
Source code in supervision/detection/utils.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
mask_to_xyxy¶
Converts a 3D np.array of 2D bool masks into a 2D np.array of bounding boxes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
masks |
ndarray
|
A 3D |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: A 2D |
Source code in supervision/detection/utils.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |