Friday , June 18 2021
Home / Computer Vision / Drawing a Rectangle on Image in Python using OpenCV

Drawing a Rectangle on Image in Python using OpenCV

7 Drawing a Rectangle

Drawing a Rectangle on Image in Python using OpenCV

In [2]:
import cv2
img = cv2.imread('machinelearning.png',1)
cv2.imshow('Machine Learning',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

Drawing a Rectangle

rectangle() function take 5 Arguments

  • Image
  • Top-left corner co-ordinates
  • Bottom-right corner co-ordinates
  • Color (in BGR format)
  • Line width
In [3]:
import cv2
img = cv2.imread('machinelearning.png',1)

output = img.copy() 
rectangle = cv2.rectangle(output, (260, 10),(460, 200), (0, 255, 0), 5) 

cv2.imshow('Machine Learning',rectangle)
cv2.waitKey(0)
cv2.destroyAllWindows()

About Machine Learning

Check Also

Record Video From a Webcam using OpenCV

12 Record Video using OpenCV Record Video From a Webcam using OpenCV¶ cv2.VideoWriter( filename, fourcc, …

Leave a Reply

Your email address will not be published. Required fields are marked *