-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.py
32 lines (24 loc) · 1.08 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from math import cos, sin
import cv2
import numpy as np
def draw_3d_axis(image, yaw, pitch, roll, origin_x=None, origin_y=None, size=50):
pitch = pitch * np.pi / 180
yaw = -(yaw * np.pi / 180)
roll = roll * np.pi / 180
if origin_x == None and origin_y == None:
h, w = image.shape[:2]
origin_x = w / 2
origin_y = h / 2
# X axis (red)
x1 = size * (cos(yaw) * cos(roll)) + origin_x
y1 = size * (cos(pitch) * sin(roll) + cos(roll) * sin(pitch) * sin(yaw)) + origin_y
cv2.line(image, (int(origin_x), int(origin_y)), (int(x1), int(y1)), (0, 0, 255), 3)
# Y axis (green)
x2 = size * (-cos(yaw) * sin(roll)) + origin_x
y2 = size * (-cos(pitch) * cos(roll) - sin(pitch) * sin(yaw) * sin(roll)) + origin_y
cv2.line(image, (int(origin_x), int(origin_y)), (int(x2), int(y2)), (0, 255, 0), 3)
# Z axis (blue)
x3 = size * (-sin(yaw)) + origin_x
y3 = size * (cos(yaw) * sin(pitch)) + origin_y
cv2.line(image, (int(origin_x), int(origin_y)), (int(x3), int(y3)), (255, 0, 0), 2)
return image