www.gusucode.com > 基于matlab的三维重建代码,提取两幅图片的匹配点源码程序 > 基于matlab的三维重建代码,提取两幅图片的匹配点源码程序/code/code/dfundamental.m

    % [F] = dfundamental(x,xp)
%
% The basic 8-point algorithm of for reconstructing
% a scene up to a projective transformation
% as described in Chapter 6, "An introduction to 3-D Vision"
% by Y. Ma, S. Soatto, J. Kosecka, S. Sastry (MASKS)
%
% Code distributed free for non-commercial use
% Copyright (c) MASKS, 2003
%
% Last modified 5/5/2003
%
%

function  F = dfundamental(p,q)

n = size(p);
NPOINTS = n(2);

%set up matrix A such that A*[v1,v2,v3,s1,s2,s3,s4,s5,s6]' = 0


Kinv(:,:,1)=eye(3,3);
Kinv(:,:,2)=eye(3,3);

% compute the normalizing transformations 
if 1
Kinv(:,:,1)=chol(inv(p*p'/size(p,2)));
p=Kinv(:,:,1)*p;

Kinv(:,:,2)=chol(inv(q*q'/size(q,2)));
q=Kinv(:,:,2)*q;
end

A = zeros(NPOINTS, 9);

if NPOINTS < 9
     error('Too few mesurements')
     return;
end

for i = 1:NPOINTS
    A(i,:) = kron(q(:,i),p(:,i))';
  end
r = rank(A);

if r < 8 
  error('Measurement matrix rank defficient');
end;

[U,S,V] = svd(A);
% pick the eigenvector corresponding to the smallest eigenvalue
f = V(:,9);

% fundamental  matrix
est = [f(1), f(2), f(3);
       f(4), f(5), f(6);
       f(7), f(8), f(9)];

f = Kinv(:,:,2)'*est*Kinv(:,:,1);

% impose the rank constraint
[U,S,V] = svd(f);
S(3,3) = 0;
F = U*S*V';