-
Notifications
You must be signed in to change notification settings - Fork 209
/
fakeslam.py
executable file
·58 lines (43 loc) · 1.08 KB
/
fakeslam.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
#!/usr/bin/env python3
import os
import sys
import time
sys.path.append("lib/macosx")
sys.path.append("lib/linux")
import numpy as np
from slam import SLAM
from renderer import Renderer
from display import Display2D, Display3D
if __name__ == "__main__":
W,H = 640,480
F = H # with 45 degree FoV
K = np.array([[F,0,W//2],[0,F,H//2],[0,0,1]])
Kinv = np.linalg.inv(K)
disp3d = Display3D()
disp2d = Display2D(W, H)
slam = SLAM(W, H, K)
r = Renderer(W, H)
fn = 0
pos_x = 0
dir_x = True
while 1:
fn += 1
# render
frame, verts = r.draw([pos_x,0,0])
# add gaussian noise
verts += np.random.normal(0.0, 0.1, verts.shape)
# ground truth pose
pose = np.eye(4)
pose[0,3] = pos_x
slam.process_frame(frame, None, verts)
disp3d.paint(slam.mapp)
img = slam.mapp.frames[-1].annotate(frame)
disp2d.paint(img)
# flip flop
if pos_x > 10:
dir_x = False
elif pos_x < -10:
dir_x = True
pos_x += 0.5 * (1 if dir_x else -1)
if fn > 20:
slam.mapp.optimize(verbose=True, local_window=None, rounds=10)