forked from VanDavv/Gaze_pointer_controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
54 lines (37 loc) · 1.62 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import numpy as np
import cv2
from math import cos, sin
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
def draw_Z_axis(image, yaw, pitch, roll, origin_x=None, origin_y=None, size = 100):
# 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
# Z axis (magenta)
x = size * (sin(yaw)) + origin_x
y = size * (-cos(yaw) * sin(pitch)) + origin_y
cv2.line(image, (int(origin_x), int(origin_y)), (int(x),int(y)),(255,255,0),2)
return image