how to draw a line knowing the starting coordinate, line length x angle and y, angle
Question:
I am trying to draw a line knowing the starting coordinate, line length x angle and y, angle. I am trying to visualize the eye gaze direction of a human in a video.
For an example, I want to draw the blue lines here:
I already have the center point of the eye (start of the blue line), and I already have the x and y angle of the eye. How do I draw this line?
I’ve found a lot of tutorials on how to draw such lines (https://learnopencv.com/head-pose-estimation-using-opencv-and-dlib/), but they involve translation and rotation vectors. Is there a clean way to do this just using the known x/y angles?
Answers:
Given a length r and an angle φ between the x-axis and your line to draw, you can calculate a coordinate for a point P(x, y) like this:
x = r * cos(φ)
y = r * sin(φ)
For example, a vertical line with r = 1; φ = 90° = π / 2 would return y = 1 * sin(π / 2) = 1
Then you can import your image in opencv
and draw a line using cv2.line
.
I am trying to draw a line knowing the starting coordinate, line length x angle and y, angle. I am trying to visualize the eye gaze direction of a human in a video.
For an example, I want to draw the blue lines here:
I already have the center point of the eye (start of the blue line), and I already have the x and y angle of the eye. How do I draw this line?
I’ve found a lot of tutorials on how to draw such lines (https://learnopencv.com/head-pose-estimation-using-opencv-and-dlib/), but they involve translation and rotation vectors. Is there a clean way to do this just using the known x/y angles?
Given a length r and an angle φ between the x-axis and your line to draw, you can calculate a coordinate for a point P(x, y) like this:
x = r * cos(φ)
y = r * sin(φ)
For example, a vertical line with r = 1; φ = 90° = π / 2 would return y = 1 * sin(π / 2) = 1
Then you can import your image in opencv
and draw a line using cv2.line
.