Draw Rectangles on Image Using cv2.rectangle() in Python OpenCV

In this tutorial, we will show you how to use cv2.rectangle() to draw some rectangles on an image in python opencv.

Best Practice to Draw Rectangles on Image Using cv2.rectangle() in Python OpenCV

1.Open an image

import cv2
img = cv2.imread('C:/Users/N/Desktop/monument.png')

2.Draw three rectangles using  cv2.rectangle()

cv2.rectangle(img, (10, 10), (100, 100), (0, 255, 0))
cv2.rectangle(img, (120, 120), (150, 150), (255, 0, 0), 5)
cv2.rectangle(img, (200, 200), (300, 400), (0, 0, 255), -1)

3.Display the resultant image

cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

Draw Rectangles on Image Using cv2.rectangle() in Python OpenCV