% findfund:
% calculates a fundamental matrix for the two specified images
%
% im1, im2 - names of two images
% f - fundamental matrix

function f = findfundmat(im1,im2)

[u,v,up,vp] = getcoords(im1,im2)

% % you may want to check how it works for the following set of points
% u = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 10; 15; 1; 1; 1; 10; 10; 10; 10; 10; 10];
% v = [6; 7; 8; 9; 10; 11; 12; 13; 9; 15; 10; 15; 2; 2; 2; 10; 10; 10; 10; 10; 10];
% 
% up = [2; 3; 4; 5; 6; 7; 8; 9; 9; 10; 10; 15; 1; 1; 1; 10; 10; 10;10; 10; 10];
% vp = [6; 7; 8; 9; 10; 11; 12; 13; 9; 15; 10; 15; 2; 2; 2; 10; 10; 10; 10; 10; 10];

F = zeros(3,3,1);

% m - no of points
[m,n] = size(u)

o = ones(m,1);

A = [u.*up u.*vp u v.*up v.*vp v up vp o]

z = zeros(m,1);

% *************** Note the format of f *************************
% Depending on how many points you choose (the more, the better)
% the size of the fundamental matrix f might be different 
% (the number of rows is always 8 but the number of column varies)
%
% to check the sufficient condition for the two views to be parallel 
% (fundamental matrix has the form F=[0 0 0; 0 0 -1; 0 1 0])
% you need to check every column of matrix f and see whether after 
% reshaping it to a 3x3 matrix it has the same values as F
% ***************************************************************
f = nulbasis(A)


end