cv3.draw.fill_poly
- cv3.draw.fill_poly(img, pts, rel=None, color=None, copy=False)[source]
Draw a filled polygon on an image.
- Parameters:
img (numpy.ndarray) – Input image to draw on.
pts (array-like) – Points defining the polygon. Can be a numpy array, list of lists, or tuple of tuples with shape (N, 2) where N is the number of points.
rel (bool, optional) – Whether to use relative coordinates. Defaults to None.
color – Color to fill the polygon (default: opt.COLOR).
copy (bool) – Whether to copy the image before drawing (default: False).
- Returns:
Image with the filled polygon drawn on it.
- Return type:
numpy.ndarray
Note
Points can be specified in various formats: - List of [x, y] coordinates: [[x1, y1], [x2, y2], …] - Tuple of (x, y) coordinates: ((x1, y1), (x2, y2), …) - Flattened list: [x1, y1, x2, y2, …] - Numpy array with shape (N, 2) or (N, 1, 2)
Relative coordinates are in the range [0, 1] where 0 is the top/left and 1 is the bottom/right of the image.
Example
>>> import cv3 >>> img = cv3.zeros(100, 100, 3) >>> points = [[10, 10], [50, 20], [90, 10], [90, 90]] >>> # Draw a filled polygon >>> img = cv3.fill_poly(img, points, color='red')