-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
till camera pose and 3D points: TODO: chirality
- Loading branch information
1 parent
7b2433a
commit 2713a8c
Showing
35 changed files
with
439 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,36 @@ | ||
import numpy as np | ||
|
||
def ExtractCameraPose(E): | ||
""" | ||
Args: | ||
E (array): Essential Matrix | ||
K (array): Intrinsic Matrix | ||
Returns: | ||
arrays: set of Rotation and Camera Centers | ||
""" | ||
|
||
W = np.array([[0,-1,0],[1,0,0],[0,0,-1]]) | ||
Z = np.array([[0,1,0],[-1,0,0],[0,0,0]]) | ||
##UPDATE | ||
U, S, V_T = np.linalg.svd(E) | ||
W = np.array([[0, -1, 0], [1, 0, 0], [0, 0, 1]]) | ||
|
||
U,S,VT = np.linalg.svd(E) | ||
S = np.dot(U, np.dot(Z, U.T)) | ||
R1 = np.dot(U, np.dot(W, VT)) | ||
R2 = np.dot(U, np.dot(W.T, VT)) | ||
# print("E svd U", U) | ||
# print("E svd S", S) | ||
# print("E svd U[:, 2]", U[:, 2]) | ||
R = [] | ||
C = [] | ||
R.append(np.dot(U, np.dot(W, V_T))) | ||
R.append(np.dot(U, np.dot(W, V_T))) | ||
R.append(np.dot(U, np.dot(W.T, V_T))) | ||
R.append(np.dot(U, np.dot(W.T, V_T))) | ||
C.append(U[:, 2]) | ||
C.append(-U[:, 2]) | ||
C.append(U[:, 2]) | ||
C.append(-U[:, 2]) | ||
|
||
t = np.array([-S[1,2],S[0,2],-S[0,1]]).reshape(3,1) | ||
|
||
P1 = np.hstack((R1, t)) | ||
P2 = np.hstack((R1, -t)) | ||
P3 = np.hstack((R2, t)) | ||
P4 = np.hstack((R2, -t)) | ||
return [P1, P2, P3, P4] | ||
for i in range(4): | ||
if (np.linalg.det(R[i]) < 0): | ||
R[i] = -R[i] | ||
C[i] = -C[i] | ||
|
||
return R, C | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import numpy as np | ||
|
||
|
||
def LinearTriangulation(K, C1, R1, C2, R2, x1, x2): | ||
|
||
I = np.identity(3) | ||
C1 = np.reshape(C1, (3, 1)) | ||
C2 = np.reshape(C2, (3, 1)) | ||
|
||
P1 = np.dot(K, np.dot(R1, np.hstack((I, -C1)))) | ||
P2 = np.dot(K, np.dot(R2, np.hstack((I, -C2)))) | ||
|
||
p1T = P1[0,:].reshape(1,4) | ||
p2T = P1[1,:].reshape(1,4) | ||
p3T = P1[2,:].reshape(1,4) | ||
|
||
p_dash_1T = P2[0,:].reshape(1,4) | ||
p_dash_2T = P2[1,:].reshape(1,4) | ||
p_dash_3T = P2[2,:].reshape(1,4) | ||
|
||
all_X = [] | ||
for i in range(x1.shape[0]): | ||
x = x1[i,0] | ||
y = x1[i,1] | ||
x_dash = x2[i,0] | ||
y_dash = x2[i,1] | ||
|
||
|
||
A = [] | ||
A.append((y * p3T) - p2T) | ||
A.append(p1T - (x * p3T)) | ||
A.append((y_dash * p_dash_3T) - p_dash_2T) | ||
A.append(p_dash_1T - (x_dash * p_dash_3T)) | ||
|
||
A = np.array(A).reshape(4,4) | ||
|
||
_, _, vt = np.linalg.svd(A) | ||
v = vt.T | ||
x = v[:,-1] | ||
all_X.append(x) | ||
return np.array(all_X) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.