1 | % vgg_line3d_linear Linear estimation of 3d line from image lines and camera matrices.
|
---|
2 | %
|
---|
3 | % SYNOPSIS
|
---|
4 | % L = vgg_line3d_from_lP_lin(s,P [,imsize]), where
|
---|
5 | %
|
---|
6 | % s ... cell(K) of double(3,3), inv. covariance matrices of the K image line segments:-
|
---|
7 | % - If the segments are estimated from edges, it is s(:,k) = x*x',
|
---|
8 | % where x (3-by-N) are homog. coordinates of the edgels with last components 1.
|
---|
9 | % - If only end points are available, s(:,k) = d*x*y' where x, y (column 2-vectors)
|
---|
10 | % are the segment's end points and d its length.
|
---|
11 | %
|
---|
12 | % P ... cell(K) of double(3,4), camera matrices
|
---|
13 | %
|
---|
14 | % imsize ... double(2,K), image sizes (for preconditioning).
|
---|
15 | % Omit if s and P are already preconditioned.
|
---|
16 | %
|
---|
17 | % L ... double(4,2), 3d straight line; columns of L are two homogeneous
|
---|
18 | % points spanning the line.
|
---|
19 |
|
---|
20 | function L = vgg_line3d_from_lP_lin(s,P,imsize)
|
---|
21 |
|
---|
22 | if nargin < 3, imsize = []; end
|
---|
23 |
|
---|
24 | K = length(P); % number of images
|
---|
25 |
|
---|
26 | % l := straight lines in homog. coords
|
---|
27 | for k = 1:K
|
---|
28 | l(k,:) = vgg_fit_hplane_to_x(s{k});
|
---|
29 | end
|
---|
30 |
|
---|
31 | if ~isempty(imsize) & K>2 % Preconditioning; for 2 views is not needed
|
---|
32 | for k = 1:K
|
---|
33 | [H,invH] = vgg_conditioner_from_image(imsize(:,k));
|
---|
34 | P{k} = H*P{k};
|
---|
35 | l(k,:) = l(k,:)*invH;
|
---|
36 | end
|
---|
37 | l = norml(l);
|
---|
38 | end
|
---|
39 |
|
---|
40 | M = [];
|
---|
41 | for k = 1:K
|
---|
42 | M = [M; l(k,:)*P{k}];
|
---|
43 | end
|
---|
44 |
|
---|
45 | [u,s,v] = svd(normx(M')',0);
|
---|
46 | L = v(:,end-1:end);
|
---|
47 |
|
---|
48 | return
|
---|
49 |
|
---|
50 |
|
---|
51 | function x = normx(x)
|
---|
52 | x = x./(ones(size(x,1),1)*sqrt(sum(x.*x)));
|
---|
53 |
|
---|
54 | function l = norml(l)
|
---|
55 | % l = norml(l) Multiplies hyperplane l by scalar so that for each n, norm(l(1:end-1,n))==1.
|
---|
56 | l = l./(sqrt(sum(l(:,1:end-1).^2,2))*ones(1,size(l,2)));
|
---|