Skip to main content

OpenCV - Drawing a line with Python

Hello Guys,

In this tutorial, I will show you how to draw a line in OpenCV.

OpenCV comes with lots of built-in functions that make our life easier especially when we are working on image processing

And there is a function called line in OpenCV which is used to draw a line.

This function takes the following parameters:

1. Image: Takes image object
2. Point 1: Point 1 X and Y  Coordinates
3. Point 2: Point 2 X and Y  Coordinates
4. Color: Takes color in BGR format
5. Thickness: By default set to 1 (optional)
6. Line Type: By default set to 8-connected.It can also be LINE_AA or 4-connected (Optional)
7. Shift: Shifts fractional bits in the point coordinates (Optional)

Well it is recommended to use line LINE_AA (
Anti Aliased) as line type.

line without AA

Line Without LINE_AA  (Anti Aliased)

You can observe the right and left ends of the line . You will notice curves are showing in a zigzag pattern. 

Line With AA

Line With LINE_AA  (Anti Aliased)

Now in this image you can observe the curves are smooth

Program

#import cv2 moduleimport cv2 as cvimg = cv.imread("nature.jpg")height,width= img.shape[0:2]#creating horizontal line at the center of image# Show curve in zigzag patternimg = cv.line(img,(100,height/2),(800,height/2),(255,144,100),50)#To avoid zigzag patten around curves of line.#LINE_AA - Stands for Line Antialiased (Creates smooth curve)"""img = cv.line(img,(100,height/2),(800,height/2), (255,144,100),50,cv.LINE_AA)"""cv.imshow('Line',img)cv.waitKey(0)cv.destroyAllWindows()

Thanks for reading 🙂 🙂

Comments

Popular posts from this blog

Automation - Update Naukri Profile Using Selenium

Recently one of my friend came to me with a problem. He is looking out for new job but he feels quite boring to update  his profile on daily basis. As some people says updating profile in the morning gives you more calls as it keeps the newly updated profile on top (Although i don’t know whether naukri works this way or not 😀 ). As i was more interested to solve his problem.  After listening his problem i came to solution that instead of updating it manually lets make this job automatic. And it is quite interesting how we can automate our daily boring task with automation. Another day i came with the solution . And the solution was to make it automatic using selenium (Those who are not aware about selenium do check this link) In short, Selenium is a Testing automation Framework. And it is for automating web applications for testing purposes, but is certainly not limited to just that. Boring web-based administration tasks can (and should) also be automated as well....

Shut Down the Computer using notepad

Open notepad >> Write @echo off msg * I am tired. shutdown -c “So, Bye Bye dear” -s >> Save the File as AnyName.bat When you will open this file, your Computer will Shut down on its own after showing the message in it. NOTE: FOR EDUCATIONAL PURPOSE ONLY.I AM NOT RESPONSIBLE FOR IF ANYTHING GOES WRONG…. 

USB is not detecting by my Computer what's wrong?

Fix For Mobile (Mass Media/Storage Mode):   • First Check out Your sd card no password on your Card • Use Pc suite mode (for fixing this problem)   • Now • Goto Device Manager • Disable that Installed Driver Now again Enable it • Now Restart Your Phone And Pc. • Connect our mobile to USB’s port • Now it prompt n installation proceed Fix For USB Not Recognized:   • Firstly Check whether Your USB port is Disabled by System or not. • Link: http://computerfunz.blogspot.com/2011/05/how-to-enable-or-disable-usb-port.html • Now Follow this Steps • Goto Device Manager or • Start • RUN type Devmgmt.msc • Now you have to search for USB Controller Hub or Universal Serial Bus controllers • Now click Properties. • Now Click on Power Management tab • >Allow the computer to turn off this device to save power >click OK. • Now Hit > Scan for hardware changes. >Now it Start Detecting New Drivers for USB.