-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathvgg_X_from_xP_lin.m
executable file
·45 lines (38 loc) · 1.07 KB
/
vgg_X_from_xP_lin.m
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
%vgg_X_from_xP_lin Estimation of 3D point from image matches and camera matrices, linear.
% X = vgg_X_from_xP_lin(x,P,imsize) computes projective 3D point X (column 4-vector)
% from its projections in K images x (2-by-K matrix) and camera matrices P (K-cell
% of 3-by-4 matrices). Image sizes imsize (2-by-K matrix) are needed for preconditioning.
% By minimizing algebraic distance.
%
% See also vgg_X_from_xP_nonlin.
% [email protected], 2003
function X = vgg_X_from_xP_lin(u,P,imsize)
if iscell(P)
P = cat(3,P{:});
end
K = size(P,3);
if nargin>2
for k = 1:K
H = [2/imsize(1,k) 0 -1
0 2/imsize(2,k) -1
0 0 1];
P(:,:,k) = H*P(:,:,k);
u(:,k) = H(1:2,1:2)*u(:,k) + H(1:2,3);
end
end
A = [];
for k = 1:K
A = [A; vgg_contreps([u(:,k);1])*P(:,:,k)];
end
% A = normx(A')';
[dummy,dummy,X] = svd(A,0);
X = X(:,end);
% Get orientation right
s = reshape(P(3,:,:),[4 K])'*X;
if any(s<0)
X = -X;
if any(s>0)
% warning('Inconsistent orientation of point match');
end
end
return