-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
81 lines (58 loc) · 2.85 KB
/
Copy pathtest.py
File metadata and controls
81 lines (58 loc) · 2.85 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
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
78
79
80
81
import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
from monovideoodometery import MonoVideoOdometery
import os
img_path = '/media/charlie/Charlie4TB/VIT/PhD/Investigacion/Monocular-Video-Odometery-master/Dataset/malaga-urban-dataset-extract-01/malaga-urban-dataset-extract-01_rectified_1024x768_Images/'
pose_path = '/media/charlie/Charlie4TB/VIT/PhD/Investigacion/Monocular-Video-Odometery-master/Dataset/malaga-urban-dataset-plain-text/malaga-urban-dataset_GPS.txt'
focal = 718.8560
pp = (607.1928, 185.2157)
R_total = np.zeros((3, 3))
t_total = np.empty(shape=(3, 1))
# Parameters for lucas kanade optical flow
lk_params = dict( winSize = (21,21),
criteria = (cv.TERM_CRITERIA_EPS | cv.TERM_CRITERIA_COUNT, 30, 0.01))
# Create some random colors
color = np.random.randint(0,255,(5000,3))
vo = MonoVideoOdometery(img_path, pose_path, focal, pp, lk_params)
traj = np.zeros(shape=(768, 1024, 3))
# mask = np.zeros_like(vo.current_frame)
# flag = False
while(vo.hasNextFrame()):
frame = vo.current_frame
# for i, (new,old) in enumerate(zip(vo.good_new, vo.good_old)):
# a,b = new.ravel()
# c,d = old.ravel()
# if np.linalg.norm(new - old) < 10:
# if flag:
# mask = cv.line(mask, (a,b),(c,d), color[i].tolist(), 2)
# frame = cv.circle(frame,(a,b),5,color[i].tolist(),-1)
# cv.add(frame, mask)
cv.imshow('frame', frame)
k = cv.waitKey(1)
if k == 27:
break
if k == 121:
flag = not flag
toggle_out = lambda flag: "On" if flag else "Off"
print("Flow lines turned ", toggle_out(flag))
mask = np.zeros_like(vo.old_frame)
mask = np.zeros_like(vo.current_frame)
vo.process_frame()
print(vo.get_mono_coordinates())
mono_coord = vo.get_mono_coordinates()
true_coord = vo.get_true_coordinates()
print("MSE Error: ", np.linalg.norm(mono_coord - true_coord))
print("x: {}, y: {}, z: {}".format(*[str(pt) for pt in mono_coord]))
print("true_x: {}, true_y: {}, true_z: {}".format(*[str(pt) for pt in true_coord]))
draw_x, draw_y, draw_z = [int(round(x)) for x in mono_coord]
true_x, true_y, true_z = [int(round(x)) for x in true_coord]
traj = cv.circle(traj, (true_x + 400, true_z + 100), 1, list((0, 0, 255)), 4)
traj = cv.circle(traj, (draw_x + 400, draw_z + 100), 1, list((0, 255, 0)), 4)
cv.putText(traj, 'Actual Position:', (140, 90), cv.FONT_HERSHEY_SIMPLEX, 0.5,(255,255,255), 1)
cv.putText(traj, 'Red', (270, 90), cv.FONT_HERSHEY_SIMPLEX, 0.5,(0, 0, 255), 1)
cv.putText(traj, 'Estimated Odometry Position:', (30, 120), cv.FONT_HERSHEY_SIMPLEX, 0.5,(255,255,255), 1)
cv.putText(traj, 'Green', (270, 120), cv.FONT_HERSHEY_SIMPLEX, 0.5,(0, 255, 0), 1)
cv.imshow('trajectory', traj)
cv.imwrite("./images/trajectory.png", traj)
cv.destroyAllWindows()