Skip to content

Commit 50dd65e

Browse files
committed
First version of the triangulation code
this includes hard coded calibration constants for the current positions of the cameras. These are very rough calibration values. We should be able to improve on this.
1 parent 2a91e2a commit 50dd65e

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

triangulate_v1.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import numpy as np
2+
from numpy import linalg as LA
3+
4+
5+
#R matrix for camera 1 (west side)
6+
R1 = np.array([[-74.2709, 637.41, -255.7461], [865.2027, 273.6518, -92.0415], [0.1602, 0.3172, -0.9347]])
7+
#T matrix for camera 1
8+
T1 = np.array([[1.3248e5], [4.1268e4], [505.0954]])
9+
P1 = np.hstack((R1, T1))
10+
11+
#R matrix for camera 2 (east side)
12+
R2 = np.array([[-20.0487, 179.5963, -666.7510], [751.5431, -397.57, -330.23], [-0.2329, -0.5675, -0.7898]])
13+
#T matrix for camera 2
14+
T2 = np.array([[3.7547e5], [3.3423e5], [907.6034]])
15+
P2 = np.hstack((R2, T2))
16+
17+
#blimp position from camera 1
18+
col_1 = 411
19+
row_1 = 382
20+
#m1 = np.array([
21+
#blimp position from camera 2
22+
col_2 = 531
23+
row_2 = 178
24+
25+
26+
#translated from matlab:
27+
28+
#Camera 1
29+
invR1 = LA.inv(R1)
30+
m1T1 = -1*T1
31+
C1 = np.dot(invR1, m1T1)
32+
x0 = C1[0]
33+
y0 = C1[1]
34+
z0 = C1[2]
35+
m1 = np.array([[col_1], [row_1], [1]]);
36+
M1 = np.dot(LA.pinv(P1), m1)
37+
x = M1[0]/M1[3]
38+
y = M1[1]/M1[3]
39+
z = M1[2]/M1[3]
40+
a = x-x0
41+
b = y-y0
42+
c = z-z0
43+
44+
#Camera 2
45+
invR2 = LA.inv(R2)
46+
m1T2 = -1*T2
47+
C2 = np.dot(invR2, m1T2)
48+
x1 = C2[0]
49+
y1 = C2[1]
50+
z1 = C2[2]
51+
m2 = np.array([[col_2], [row_2], [1]]);
52+
M2 = np.dot(LA.pinv(P2), m2)
53+
x = M2[0]/M2[3]
54+
y = M2[1]/M2[3]
55+
z = M2[2]/M2[3]
56+
d = x-x1
57+
e = y-y1
58+
f = z-z1
59+
60+
A11 = (a*a + b*b + c*c)
61+
A12 = -1*(a*d + e*b + f*c)
62+
A21 = -1*(a*d + e*b + f*c)
63+
A22 = d*d + e*e + f*f
64+
A = np.array([[A11, A12], [A21, A22]])
65+
A = np.squeeze(A) #get rid of 3rd dimension
66+
v = np.array([[(x1-x0)*a + (y1-y0)*b + (z1-z0)*c], [(x0-x1)*d + (y0-y1)*e + (z0-z1)*f]])
67+
v = np.squeeze(v) #get rid of 3rd dimension
68+
invA = LA.inv(A)
69+
r = np.dot(invA,v)
70+
x_coord = x0+a*r[0]
71+
y_coord = y0+b*r[0]
72+
z_coord = z0+c*r[0]

0 commit comments

Comments
 (0)