Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw a line using an angle and a point in OpenCV

Tags:

I have a point and an angle in OpenCV, how can I draw that using those parameters and not using 2 points?

Thanks so much!

like image 478
DualSim Avatar asked Mar 07 '14 14:03

DualSim


People also ask

How do you draw a line with an angle in OpenCV?

x = (int)round(P1. x + length * cos(angle * CV_PI / 180.0)); P2. y = (int)round(P1. y + length * sin(angle * CV_PI / 180.0));

How do I draw a line in OpenCV?

Python - OpenCV & PyQT5 together You can draw a line on an image using the method line() of the imgproc class. Following is the syntax of this method. mat − A Mat object representing the image on which the line is to be drawn.

Which function is used to draw lines in OpenCV?

cv2. line() method is used to draw a line on any image.


1 Answers

Just use the equation

x2 = x1 + length * cos(θ) y2 = y1 + length * sin(θ)  

and θ should be in radians

θ = angle * 3.14 / 180.0 

In OpenCV you can rewrite the above equation like

int angle = 45; int length = 150; Point P1(50,50); Point P2;  P2.x =  (int)round(P1.x + length * cos(angle * CV_PI / 180.0)); P2.y =  (int)round(P1.y + length * sin(angle * CV_PI / 180.0)); 

Done!

like image 119
Haris Avatar answered Oct 05 '22 10:10

Haris