cv2.rectangle Python Guide: Draw & Style
The function cv2.rectangle in Python serves the following purpose:
- Draw a rectangle: Using the cv2.rectangle function, you can draw a rectangle by specifying the coordinates of the top-left and bottom-right corners to determine its position and size.
- To adjust the color and thickness of a rectangle, you can use the cv2.rectangle function. Simply specify the color with the ‘color’ parameter and the line thickness with the ‘thickness’ parameter.
- Draw a filled rectangle: In addition to drawing a hollow rectangle, you can also draw a filled rectangle by setting the parameter thickness to -1, which effectively fills the inside of the rectangle with the specified color.
- Multiple rectangles can be drawn by calling the cv2.rectangle function multiple times within a loop.
- The result of drawing can be retrieved by the cv2.rectangle function, and it can be assigned to a variable for further operations, such as displaying the image.