- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Draw rectangle on an image using OpenCV
In this program, we will draw a rectangle using the OpenCV function rectangle(). This function takes some parameters like starting coordinates, ending coordinates, color and thickness and the image itself.
Step 1: Import cv2. Step 2: Read the image using imread(). Step 3: Define the starting coordinates. Step 5: Define the ending coordinates. Step 6: Define the color and the thickness. Step 7: Draw the rectangle using the cv2.reactangle() function. Step 8: Display the rectangle.
import cv2 image = cv2.imread('testimage.jpg') height, width, channels = image.shape start_point = (0,0) end_point = (width, height) color = (0,0,255) thickness = 5 image = cv2.rectangle(image, start_point, end_point, color, thickness) cv2.imshow('Rectangle',image)
- Related Articles
- Draw an ellipse on an image using OpenCV
- Draw a line on an image using OpenCV
- How to draw markers on an image using Java OpenCV library?
- How to draw polylines on an image in OpenCV using Python?
- How to draw an arrowed line on an image in OpenCV Python?
- How to draw geometrical shapes on image using OpenCV Java Library?
- Performing an opening operation on an image using OpenCV
- Performing binary thresholding on an image using OpenCV
- Performing truncate thresholding on an image using OpenCV
- Performing zero thresholding on an image using OpenCV
- How to draw a rectangle in OpenCV using Java?
- How to draw a rectangle in OpenCV using C++?
- How to detect a rectangle and square in an image using OpenCV Python?
- Histogram equalization on an image in OpenCV using Java.
- Performing inverse binary thresholding on an image using OpenCV