In this tutorial, we will show you how to use cv2.rectangle() to draw some rectangles on an image 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()