Geometry
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 |
---|---|---|---|
polygon |
ndarray
|
A 2-dimensional numpy ndarray representing the vertices of the polygon. |
required |
Returns:
Name | Type | Description |
---|---|---|
Point |
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]])
sv.get_polygon_center(polygon=polygon)
# Point(x=1, y=1)
Source code in supervision/geometry/utils.py
Bases: Enum
Enum representing the position of an anchor point.