% RANSACFITFUNDMATRIX - fits fundamental matrix using RANSAC % % Usage: [F, inliers] = ransacfitfundmatrix(x1, x2, t, acc, maxit, nrtrials, low, ner) % % Arguments: % x1 - 2xN or 3xN set of homogeneous points. If the data is % 2xN it is assumed the homogeneous scale factor is 1. % x2 - 2xN or 3xN set of homogeneous points such that x1<->x2. % % s - The minimum number of samples from x required by % fittingfn to fit a model. % % t - The distance threshold between data point and the model % used to decide whether a point is an inlier or not. % Note that point coordinates are normalised to that their % mean distance from the origin is sqrt(2). The value of % t should be set relative to this, say in the range % 0.001 - 0.01 % acc - The same as above but is used to prune the set. If acc ninliers % Record best solution ninliers = length(inliers); bestF = F{k}; bestInliers = inliers; end end else % We just have one solution x2tFx1 = zeros(1,length(x1)); for n = 1:length(x1) x2tFx1(n) = x2(:,n)'*F*x1(:,n); end Fx1 = F*x1; Ftx2 = F'*x2; % Evaluate distances d = x2tFx1.^2 ./ ... (Fx1(1,:).^2 + Fx1(2,:).^2 + Ftx2(1,:).^2 + Ftx2(2,:).^2); bestInliers = find(abs(d) < t); % Indices of inlying points bestF = F; % Copy F directly to bestF end