• 大小: 71KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-19
  • 语言: 其他
  • 标签: harris角点  ransac  

资源简介

利用harris算法提取角点,ncc进行匹配,最后使用ransac算法删除错误匹配点

资源截图

代码片段和文件信息

function [F inliers] = FindFund(x1 x2 t feedback)

    if ~all(size(x1)==size(x2))
        error(‘Data sets x1 and x2 must have the same dimension‘);
    end
    
    if nargin == 3
feedback = 0;
    end
    
    [rowsnpts] = size(x1);
    if rows~=2 & rows~=3
        error(‘x1 and x2 must have 2 or 3 rows‘);
    end
    
    if rows == 2    % Pad data with homogeneous scale factor of 1
        x1 = [x1; ones(1npts)];
        x2 = [x2; ones(1npts)];        
    end
    
    % Normalise each set of points so that the origin is at centroid and
    % mean distance from origin is sqrt(2).  
    [x1 T1] = normalise(x1);
    [x2 T2] = normalise(x2);

    s = 8;  % 8-point
    
    fittingfn = @fundmatrix;
    distfn    = @funddist;
    degenfn   = @isdegenerate;
    [F inliers] =ransac([x1; x2] fittingfn distfn degenfn s t feedback);
    %do a final least squares fit on the data points 
    F = fundmatrix(x1(:inliers) x2(:inliers)); 
    % Denormalise
    F = T2‘*F*T1;
  %check if is degenerated  
function r = isdegenerate(x)
    r = 0; 
    
% Function to evaluate Sampson distance of the fit of a fundamental matrix
% with respect to a  set of matched points as needed by RANSAC.   
    function [bestInliers bestFV_ar] = funddist(F x t);
    
    x1 = x(1:3:);    % Extract x1 and x2 from x
    x2 = x(4:6:);
    
    
    if iscell(F)  % several solutions each of which must be tested
  
nF = length(F);   % Number of solutions to test
bestF = F{1};     % Initial allocation of best solution
ninliers = 0;     % Number of inliers

for k = 1:nF
    x2tFx1 = zeros(1length(x1));
    for n = 1:length(x1)
x2tFx1(n) = x2(:n)‘*F{k}*x1(:n);
    end
    
    Fx1 = F{k}*x1;
    Ftx2 = F{k}‘*x2;     

    % Evaluate distances
    d =  x2tFx1.^2 ./ ...
 (Fx1(1:).^2 + Fx1(2:).^2 + Ftx2(1:).^2 + Ftx2(2:).^2);
    
    inliers = find(abs(d) < t);     % Indices of inlying points
                                         
    
    if length(inliers) > ninliers   % Record best solution
ninliers = length(inliers);
bestF = F{k};
bestInliers = inliers;
    end
end
    
    else     % We just have one solution
x2tFx1 = zeros(1length(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(x2tFx1)     bestF = F;    
    if(size(bestInliers2)<4)
        V_ar=1;
    else
V_ar=var(x2tFx1(:bestInliers‘));
     end
    end
    % computes fundamental matrix from 8 or more points
function [Fe1e2] = fundmatrix(varargin)
    
    [x1 x2 npts] = validate(varargin(:));
    Octave = exist(‘OCTAVE_VERSION‘) ~= 0;
    % Normalise each set of points so that the origin 
    [x1 T1] = normalise(x1);
    [x2 T2] = normalise(x2);
 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       3694  2012-03-29 15:44  zhisong_chen_project3\FindFund.m

     文件       2711  2012-03-22 15:54  zhisong_chen_project3\harris.m

     文件      37750  2012-03-22 15:14  zhisong_chen_project3\im1.jpg

     文件      38250  2012-03-22 15:15  zhisong_chen_project3\im2.jpg

     文件       1973  2012-03-29 15:58  zhisong_chen_project3\main.m

     文件       1699  2012-03-29 15:35  zhisong_chen_project3\NCC.m

     文件       1133  2012-03-29 14:15  zhisong_chen_project3\normalise.m

     文件       2460  2012-03-29 15:44  zhisong_chen_project3\ransac.m

     文件        739  2012-03-22 18:17  zhisong_chen_project3\validate.m

     目录          0  2012-04-21 17:01  zhisong_chen_project3

----------- ---------  ---------- -----  ----

                90409                    10


评论

共有 条评论