- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- 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 a line on an image using OpenCV
In this program, we will draw a simple line on an image using the OpenCV function line().
Original Image
Algorithm
Step 1: Import cv2. Step 2: Read the image using imread(). Step 3: Get the dimensions of the image using the image.shape method. Step 4: Define starting point of the line. Step 5: Define the end point of the line. Step 6: Define the thickness of the line. Step 7: Draw the line using the cv2.line() function and pass Step 3 to Step 4 as parameters.
Example Code
import cv2 image = cv2.imread('testimage.jpg') height, width, channels = image.shape startpoint = (0, 0) endpoint = (height, width) thickness = 9 color = (255, 0, 0) image = cv2.line(image, startpoint, endpoint, color, thickness) cv2.imshow('Line', image)
Output
Explanation
As you can see, a blue line is drawn on the image.
Advertisements