-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_triangulation.py
133 lines (83 loc) · 3.57 KB
/
test_triangulation.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 23 14:44:00 2020
@author: johny
"""
import numpy as np
import cv2
from pose_estimation import exteriorOrient_points
import pandas as pd
def coords(event, x, y, flags, param):
global k
global l
if event == cv2.EVENT_LBUTTONDOWN:
k += 1
print(x,y)
if k <= 4:
imgp4[k] = (x, y)
else:
l += 1
imgp3[l] = (x, y)
def triangulate(imgp4, imgp3, projL = np.load('C:/Users/vero pc/Desktop/ΔΙΠΛΩΜΑΤΙΚΗ_lastTry/left_camera_info/projection_matrixL.npy'), \
projR = np.load('C:/Users/vero pc/Desktop/ΔΙΠΛΩΜΑΤΙΚΗ_lastTry/right_camera_info/projection_matrixR.npy')):
test_points = cv2.triangulatePoints(projL, projR, imgp4, imgp3)
test_points = test_points[:3, :] / test_points[3, :]
test_points = np.around(test_points, 3)
return test_points
def diffs(test_coordinates, Coords):
cols = ['dx', 'dy', 'dz']
test_list = []
rms = []
inputt = input('Give the points you hit: ').strip().split(',')
for i, inp in enumerate(inputt):
if int(inp) in Coords[0]:
test_list.append(Coords.iloc[int(inp) - 1, 1:] - \
test_coordinates[:, i])
rms.append(np.sqrt(np.mean(test_list[i]**2)))
result = pd.DataFrame(test_list, index = inputt)
result.columns = cols
result['RMSE (m)'] = rms
print(np.round(result, 3))
return (result)
result = pd.DataFrame(test_list, index = inputt)
result.columns = cols
print(np.round(result, 3))
return (result)
imgp3 = {}
imgp4 = {}
k = 0
l = 0
mtxR = np.load('C:/Users/vero pc/Desktop/ΔΙΠΛΩΜΑΤΙΚΗ_lastTry/right_camera_info/right_camera.npy')
distR = np.load('C:/Users/vero pc/Desktop/ΔΙΠΛΩΜΑΤΙΚΗ_lastTry/right_camera_info/right_distortion.npy')
mtxL = np.load('C:/Users/vero pc/Desktop/ΔΙΠΛΩΜΑΤΙΚΗ_lastTry/left_camera_info/left_camera.npy')
distL = np.load('C:/Users/vero pc/Desktop/ΔΙΠΛΩΜΑΤΙΚΗ_lastTry/left_camera_info/left_distortion.npy')
video_left = cv2.VideoCapture('C:/Users/vero pc/Desktop/ΔΙΠΛΩΜΑΤΙΚΗ_lastTry/left_cutt_video.mp4')
video_right = cv2.VideoCapture('C:/Users/vero pc/Desktop/ΔΙΠΛΩΜΑΤΙΚΗ_lastTry/right_cutt_video.mp4')
Coords = pd.read_csv('C:/Users/vero pc/Desktop/ΔΙΠΛΩΜΑΤΙΚΗ_lastTry/coords.txt', sep=",", header=None)
while(1):
try:
ret4, frame4 = (lambda video_left : video_left.read())(video_left)
ret3, frame3 = (lambda video_right : video_right.read())(video_right)
if ret4 == False or ret3 == False:
raise ValueError('Frame has not been read properly.')
except(IndexError):
print('something went wrong')
continue
frames = [cv2.undistort(np.float64(frame4), mtxL, distL),\
cv2.undistort(np.float64(frame3), mtxR, distR)]
# frames = [frame4, frame3]
for i, frame in enumerate(frames):
cv2.namedWindow('Camera', cv2.WINDOW_NORMAL)
cv2.imshow( 'Camera', frame / 255.0)
cv2.setMouseCallback('Camera', coords)
while True:
if cv2.waitKey(1) & 0xFF == 27:
cv2.destroyAllWindows()
break
break
imgp4 = exteriorOrient_points(imgp4)
imgp3 = exteriorOrient_points(imgp3)
test_coordinates = triangulate(imgp4, imgp3)
results = diffs(test_coordinates, Coords)
np.save("test_points.npy", test_coordinates)