-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrun_slam.py
executable file
·67 lines (49 loc) · 2.01 KB
/
run_slam.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
import numpy as np
import cv2
import argparse
from core.model import VisualSLAM
from core.dataset import KittiDataset
from core.utils import draw_trajectory
from core.display2D import Displayer
from core.display3D import Viewer3D
def parse_argument():
parser=argparse.ArgumentParser()
parser.add_argument('--dataset', default='kitti')
parser.add_argument('--path', required=True)
parser.add_argument('--optimize', action='store_true', help='enable pose graph optimization')
parser.add_argument('--local_window', default=10, type=int, help='number of frames to run the optimization')
parser.add_argument('--num_iter', default=100, type=int, help='number of max iterations to run the optimization')
return parser.parse_args()
def main():
args = parse_argument()
# Get data params using the dataloader
dataset = KittiDataset(args.path)
camera_matrix = dataset.intrinsic
ground_truth_poses = dataset.ground_truth
num_frames = len(dataset)
# Initialise the mono-VO model
model = VisualSLAM(camera_matrix, ground_truth_poses, args)
# Initialie the viewer object
viewer = Viewer3D()
error = []
# Iterate over the frames and update the rotation and translation vectors
for index in range(num_frames):
frame, _ , _ = dataset[index]
model(index, frame)
if index>2:
viewer.update(model)
if index>2:
x, y, z = model.cur_t[0], model.cur_t[1], model.cur_t[2]
else:
x, y, z = 0., 0., 0.
## Set ofset to remove the overlap
offset_x, offset_y = 5, 5
draw_x, draw_y =int(x) + 290 - offset_x, int(z) + 290 - offset_y
true_x, true_y = int(model.trueX) + 290, int(model.trueZ) + 290
#draw_trajectory(blank_slate, index, x, y, z, draw_x, draw_y, true_x, true_y)
cv2.imshow('Road facing camera', frame)
cv2.waitKey(1)
viewer.update(model)
viewer.stop()
if __name__ == "__main__":
main()