Polygons 工具¶
supervision.detection.utils.polygons.filter_polygons_by_area(polygons, min_area=None, max_area=None)
¶
Filters a list of polygons based on their area.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
List[ndarray]
|
A list of polygons, where each polygon is
represented by a NumPy array of shape |
required |
|
Optional[float]
|
The minimum area threshold. Only polygons with an area greater than or equal to this value will be included in the output. If set to None, no minimum area constraint will be applied. |
None
|
|
Optional[float]
|
The maximum area threshold. Only polygons with an area less than or equal to this value will be included in the output. If set to None, no maximum area constraint will be applied. |
None
|
Returns:
Type | Description |
---|---|
list[ndarray]
|
List[np.ndarray]: A new list of polygons containing only those with areas within the specified thresholds. |
Source code in supervision/detection/utils/polygons.py
supervision.detection.utils.polygons.approximate_polygon(polygon, percentage, epsilon_step=0.05)
¶
Approximates a given polygon by reducing a certain percentage of points.
This function uses the Ramer-Douglas-Peucker algorithm to simplify the input polygon by reducing the number of points while preserving the general shape.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
ndarray
|
A 2D NumPy array of shape |
required |
|
float
|
The percentage of points to be removed from the
input polygon, in the range |
required |
|
float
|
Approximation accuracy step. Epsilon is the maximum distance between the original curve and its approximation. |
0.05
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: A new 2D NumPy array of shape |