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!
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));
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.
cv2. line() method is used to draw a line on any image.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With