cv2.rectangle Python Guide: Draw & Style

The function cv2.rectangle in Python serves the following purpose:

  1. 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.
  2. 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.
  3. 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.
  4. Multiple rectangles can be drawn by calling the cv2.rectangle function multiple times within a loop.
  5. 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.
bannerAds