-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtriangulate.m
More file actions
27 lines (20 loc) · 797 Bytes
/
triangulate.m
File metadata and controls
27 lines (20 loc) · 797 Bytes
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
function P = triangulate(M1, p1, M2, p2)
P = [];
for i = 1:size(p1, 1)
% Save off p1 and p2 for easy access
v1 = p1(i, :);
v2 = p2(i, :);
% Calculate least squares error to algebraic reprojection error
% Here we are computing |vi x MiP|
A = [v1(2).*M1(3, :)-M1(2, :); M1(1, :) - v1(1).*M1(3, :); v1(1).*M1(2, :)-v1(2).*M1(1, :); ...
v2(2).*M2(3, :)-M2(2, :); M2(1, :) - v2(1).*M2(3, :); v2(1).*M2(2, :)-v2(2).*M2(1, :)];
% Vector that minimzies the solution to |vi x MiP| is the
% minimum eigenvector of A^T A
[~, ~, V] = svd(A);
p = V(:, end)';
% Normalize the current P
p = p ./ p(4);
% Save in vector of P's
P = [P; p];
end
end