cv3.draw.rectangles
- cv3.draw.rectangles(img: array, rects: List[List], *args, **kwargs) array[source]
Draw multiple rectangles on an image. See
rectangle()for more details.- Parameters:
img (numpy.ndarray) – Input image to draw on.
rects (List[List]) – List of rectangles, where each rectangle is a list of parameters to pass to the rectangle function.
*args – Additional arguments to pass to the
rectangle()function.**kwargs – Additional keyword arguments to pass to the
rectangle()function.
- Returns:
Image with all rectangles drawn on it.
- Return type:
numpy.ndarray
Note
Each rectangle in the rects list should contain the parameters needed for the rectangle function (x0, y0, x1, y1, etc.).
The coordinate modes are: - ‘xyxy’: Two corner points (x0, y0) and (x1, y1) - ‘xywh’: Top-left corner (x0, y0) and width (x1), height (y1) - ‘ccwh’: Center point (x0, y0) and width (x1), height (y1)
Relative coordinates are in the range [0, 1] where 0 is the top/left and 1 is the bottom/right of the image.
When fill=True, the rectangles are filled regardless of the thickness value. When fill=False, the rectangles are outlined with the specified thickness. When fill=None (default), the rectangles are filled if t=-1, otherwise outlined.
Example
>>> import cv3 >>> img = cv3.zeros(100, 100, 3) >>> # Draw multiple rectangles >>> rectangles = [ ... [10, 10, 30, 30], ... [40, 40, 60, 60], ... [70, 70, 90, 90] ... ] >>> img = cv3.rectangles(img, rectangles, color='red', t=2) >>> # Draw multiple filled rectangles >>> filled_rectangles = [ ... [15, 15, 35, 35], ... [45, 45, 65, 65] ... ] >>> img = cv3.rectangles(img, filled_rectangles, color='blue', fill=True)