[37] | 1 | % vgg_mrdivs Solves equation system Y*diag(s) = A*X with unkowns A, s.
|
---|
| 2 | %
|
---|
| 3 | % A = vgg_mrdivs(X,Y) solves (overdetermined) equation system Y*diag(s) = A*X
|
---|
| 4 | % by linear method (DLT algorithm).
|
---|
| 5 | % Parameters:
|
---|
| 6 | % X ... double (N,K)
|
---|
| 7 | % Y ... double (M,K)
|
---|
| 8 | % A ... double (M,N)
|
---|
| 9 | % s ... double (1,K)
|
---|
| 10 | %
|
---|
| 11 | % Preconditioning of the points not included in the function. Use vgg_conditioner_*.
|
---|
| 12 | %
|
---|
| 13 | % Typical usage:
|
---|
| 14 | % 1. Estimating an image homography from K pairs of corresponding points.
|
---|
| 15 | % If 3-by-K matrices x and y are the points in homogeneous coordinates, the 3-by-3 homography
|
---|
| 16 | % matrix is obtained as H = vgg_mrdivs(x,y).
|
---|
| 17 | %
|
---|
| 18 | % 2. Estimating 3-by-4 camera projection matrix P from corresponding pairs of image and scene points.
|
---|
| 19 | % For image points x (3xK matrix) and scene points X (4xK matrix) do P = vgg_mrdivs(X,x).
|
---|
| 20 |
|
---|
| 21 | % (c) werner@robots.ox.ac.uk
|
---|
| 22 |
|
---|
| 23 | % Algorithm:
|
---|
| 24 | %
|
---|
| 25 | % For n-th point pair X(:,n) and Y(:,n) we have
|
---|
| 26 | % s*X(:,n) = A*Y(:,n)
|
---|
| 27 | % We eliminate s what results in MY*(MY-1)/2 linear homogenous equations
|
---|
| 28 | % for elements of A. We solve this system by svd or eig.
|
---|
| 29 |
|
---|
| 30 | function A = vgg_mrdivs(X,Y)
|
---|
| 31 |
|
---|
| 32 | [MX,N] = size(X);
|
---|
| 33 | [MY,NY] = size(Y);
|
---|
| 34 | if N ~= NY, error('Matrices A, B must have equal number of columns.'); end
|
---|
| 35 |
|
---|
| 36 | % construct the measurement matrix
|
---|
| 37 | W = zeros(MX*MY,MY*(MY-1)/2*N);
|
---|
| 38 | k = 1;
|
---|
| 39 | for i = 1:MY
|
---|
| 40 | for j = 1:i-1
|
---|
| 41 | W([[1:MX]+MX*(j-1) [1:MX]+MX*(i-1)],[1:N]+N*(k-1)) = [(ones(MX,1)*Y(i,:)).*X; -(ones(MX,1)*Y(j,:)).*X];
|
---|
| 42 | k = k+1;
|
---|
| 43 | end
|
---|
| 44 | end
|
---|
| 45 |
|
---|
| 46 | % solve the system || A'(:)' * W || ---> min
|
---|
| 47 | [dummy,s,A] = svd(W',0);
|
---|
| 48 | A = reshape(A(:,end),MX,MY)';
|
---|
| 49 |
|
---|
| 50 | return |
---|