Geometry
supervision.geometry.utils.get_polygon_center(polygon: npt.NDArray[np.float64]) -> Point
¶
Calculate the center of a polygon. The center is calculated as the center of the solid figure formed by the points of the polygon
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
NDArray[float64]
|
A 2-dimensional numpy ndarray representing the vertices of the polygon. |
required |
Returns:
| Type | Description |
|---|---|
Point
|
The center of the polygon, represented as a Point object with x and y attributes. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the polygon has no vertices. |
Examples:
>>> import numpy as np
>>> import supervision as sv
>>> polygon = np.array([[0, 0], [0, 2], [2, 2], [2, 0]])
>>> center = sv.get_polygon_center(polygon=polygon)
>>> float(center.x)
1.0
>>> float(center.y)
1.0
Source code in src/supervision/geometry/utils.py
supervision.geometry.core.Position
¶
Bases: Enum
Enum representing the position of an anchor point.