-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransforms.py
More file actions
51 lines (46 loc) · 1.31 KB
/
transforms.py
File metadata and controls
51 lines (46 loc) · 1.31 KB
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
import numpy as np
# def get_optical_coords(M, feature):
# """
# fsu 0 cu 0
# 0 fsv cv 0
# 0 0 0 fsub
# """
# disparity = feature[0] - feature[2]
# fsub = M[2, 3]
# z = fsub / disparity
# x = (feature[0] - M[0, 2]) * z / M[0, 0]
# y = (feature[1] - M[1, 2]) * z / M[1, 1]
# return np.array([[x, y, z,1]]).T
#
#
# def imuTcam(imu_T_cam, M, feature):
# """
#
# """
# optical_coords = get_optical_coords(M, feature)
# m = np.dot(imu_T_cam,optical_coords)
# return m[:-1]
def get_optical_coords(M, feature):
"""
fsu 0 cu 0
0 fsv cv 0
0 0 0 fsub
"""
disparity = feature[0, :, :] - feature[2, :, :] # 1xMxTs
fsub = np.ones(disparity.shape) * M[2, 3]
z = np.divide(fsub, disparity) # 1xMxTs
x = (feature[0, :, :] - M[0, 2]) * z / M[0, 0]
y = (feature[1, :, :] - M[1, 2]) * z / M[1, 1]
z = z.reshape(1, -1)
x = x.reshape(1, -1)
y = y.reshape(1, -1)
homogeneous = np.ones(x.shape)
optical_coords = np.concatenate((x, y, z, homogeneous))
return optical_coords
def imuTcam(imu_T_cam, M, feature):
"""
features : 4 x M x Ts
"""
optical_coords = get_optical_coords(M, feature)
m = np.dot(imu_T_cam, optical_coords) #4 x (M*Ts)
return m[:-1]