cv3.draw.polylines
- cv3.draw.polylines(img, pts, is_closed=False, rel=None, color=None, t=None, line_type=None, copy=False)[source]
Draw polylines on an image.
- Parameters:
img (numpy.ndarray) – Input image to draw on.
pts (array-like) – Points defining the polylines. Can be a numpy array, list of lists, or tuple of tuples with shape (N, 2) where N is the number of points.
is_closed (bool, optional) – Whether to close the polyline by connecting the last point to the first. Defaults to False.
rel (bool, optional) – Whether to use relative coordinates. Defaults to None.
color – Color of the polylines (default: opt.COLOR).
t – Thickness of the lines (default: opt.THICKNESS).
line_type – Type of line for drawing (default: opt.LINE_TYPE).
copy (bool) – Whether to copy the image before drawing (default: False).
- Returns:
Image with the polylines 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 open polylines >>> img = cv3.polylines(img, points, color='red', t=2) >>> # Draw closed polylines >>> img = cv3.polylines(img, points, is_closed=True, color='blue')