-
Notifications
You must be signed in to change notification settings - Fork 0
/
trad_vo_runner.py
77 lines (59 loc) · 2.38 KB
/
trad_vo_runner.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import cv2
import pandas as pd
from tqdm import tqdm
from pinhole_camera import PinholeCamera
from traditional_visual_odometry import TraditionalVisualOdometry
from visualizer import Visualizer
import pytransform3d.rotations as py3drot
class VisualOdometryRunner:
def __init__(self):
self.visualization = False
def traditional_vo(self, input_address='D:\\V1_01_easy\\', output_name='default.csv', save_as_csv=False):
counter = 0
output_name = 'in_process_data\\' + output_name
xlist = []
ylist = []
zlist = []
rwlist = []
rxlist = []
rylist = []
rzlist = []
cam1 = PinholeCamera(752, 480, 457.587, 456.134, 379.999, 255.238)
vis = Visualizer()
vo = TraditionalVisualOdometry(cam1,vis)
cam1_path = input_address + 'mav0\\cam1\\data\\'
cam1_path_csv = input_address + 'mav0\\cam0\\data.csv'
timestamps = pd.read_csv(cam1_path_csv)['#timestamp [ns]']
for f in tqdm(timestamps):
counter = counter + 1
img = cv2.imread(cam1_path + str(f) + '.png', 0)
vo.update(img)
cur_t = vo.cur_t
cur_r = vo.cur_R
if counter >= 2:
x0, y0, z0 = cur_t[0][0], cur_t[1][0], cur_t[2][0]
cur_r0 = py3drot.quaternion_from_matrix(cur_r)
rw0, rx0, ry0, rz0 = cur_r0
else:
x0, y0, z0 = 0., 0., 0.
rw0, rx0, ry0, rz0 = 0., 0., 0., 0.
xlist.append(x0)
ylist.append(y0)
zlist.append(z0)
rwlist.append(rw0)
rxlist.append(rx0)
rylist.append(ry0)
rzlist.append(rz0)
dict = {'#timestamp [ns]': timestamps, 'predicted_x': xlist, 'predicted_y': ylist, 'predicted_z': zlist,
'predicted_r_w': rwlist, 'predicted_r_x': rxlist, 'predicted_r_y': rylist, 'predicted_r_z': rzlist}
output = pd.DataFrame(dict)
if save_as_csv:
output.to_csv(output_name, index=False)
print('csv saved')
else:
print('Traditional_VisualO_dometry accomplished')
return output
#
# if __name__ == "__main__":
# runner = VisualOdometryRunner()
# runner.traditional_vo(input_address='D:\\V1_01_easy\\', save_as_csv=False)