source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/zisserman/vgg_multiview/vgg_F_from_7pts_2img.m @ 173

Last change on this file since 173 was 37, checked in by (none), 15 years ago

Added original make3d

  • Property svn:executable set to *
File size: 1.5 KB
Line 
1%vgg_F_from_7pts_2img  Computes fundamental matrix from 7 points across 2 images.
2%
3%   [P,X] = vgg_F_from_7pts_2img(x), where
4%      x ... double(3,7,2) or cell{2} of double(3,7), 7 homogeneous points in 2 images
5%      F ... double(3,3), fundamental matrix
6%   There are 0 to 3 solutions for F. Solutions are pruned by requirement that
7%   scalars s in all equations s*cross(e1,x1)==F*x2 are positive.
8%   In case of multiple solutions, F has one dimension
9%   more such that F(:,:,n) is the n-th solution.
10%
11%   Also the form F = vgg_F_from_7pts_2img(x1,x2) is accepted.
12
13function F = vgg_F_from_7pts_2img(x1,x2)
14
15if nargin==1
16  if iscell(x1)
17    x2 = x1{2};
18    x1 = x1{1};
19  else
20    x2 = x1(:,:,2);
21    x1 = x1(:,:,1);
22  end
23end
24if any(size(x1)~=[3 7]) | any(size(x2)~=[3 7])
25  error('Wrong size of input points.');
26end
27
28% Linear step
29A = vgg_vec_swap(x1,x2)';
30[u,s,v] = svd(A,0);
31FF{1} = reshape(v(:,end-1),[3 3]);
32FF{2} = reshape(v(:,end  ),[3 3]);
33
34% Solving cubic equation and getting 1 or 3 solutions for F
35a = vgg_singF_from_FF(FF);
36F = [];
37for i = 1:length(a)
38  Fi = a(i)*FF{1} + (1-a(i))*FF{2};
39  %for n = 1:7, disp(norm(x(:,n,1)'*Fi*x(:,n,2))), end  % test code
40  if signs_OK(Fi,x1,x2)
41    F = cat(3, F, Fi);
42  end
43end
44
45return
46
47%%%%%%%%%%%%%%%%%%%%%%%%%
48
49% Checks sign consistence of F and x
50function OK = signs_OK(F,x1,x2)
51[u,s,v] = svd(F');
52e1 = v(:,3);
53l1 = vgg_contreps(e1)*x1;
54s = sum( (F*x2) .* l1 );
55OK = all(s>0) | all(s<0);
56return
Note: See TracBrowser for help on using the repository browser.