-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain_mono_vo.py
53 lines (41 loc) · 1.24 KB
/
main_mono_vo.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
import numpy as np
import os
import time
import cv2
from vo import VisualOdometry
from visualization import PangoVisualizer
np.set_printoptions(formatter={"float": lambda x: "{0:0.3f}".format(x)})
def main():
# --------- Init Camera Camera ---------
capLeft = cv2.VideoCapture(0)
with open(os.path.join("KITTI_sequence_1", "calib.txt"), "r") as f:
params = np.fromstring(f.readline(), dtype=np.float64, sep=" ")
P = np.reshape(params, (3, 4))
K = P[0:3, 0:3]
running = True
fx = K[0, 0]
cx = K[0, 2]
cy = K[1, 2]
baseline = 0.5
vo = VisualOdometry(cx, cy, fx, baseline)
vis = PangoVisualizer()
while capLeft.isOpened() and running:
ret, cv_img_left = capLeft.read()
if ret:
start = time.time()
vo.process_frame(cv_img_left)
vis.update(vo.poses)
key = cv2.waitKey(1)
if key == "q":
running = False
break
curr = time.time()
latency = 1.0 / (curr - start)
print(f"Running at {latency} hz")
start = curr
else:
running = False
capLeft.release()
cv2.destroyAllWindows()
if __name__ == "__main__":
main()