用来调试的matlab代码
%-------------------------------------------------------------------------
% As-Projective-As-Possible Image Stitching with Moving DLT
% (Patent Pending)
%-------------------------------------------------------------------------
% The demo code in this package implements the non-rigid image stitching
% method proposed in:
%
% "As-Projective-as-Possible Image Stitching with Moving DLT"
% Julio Zaragoza, Tat-Jun Chin, Michael Brown and David Suter,
% In Proc. Computer Vision and Pattern Recognition, Portland, Oregon, USA, 2013.
%
% Copyright (c) 2013-2014 Julio Zaragoza and Tat-Jun Chin
% School of Computer Science, The University of Adelaide, South Australia
% http://www.cs.adelaide.edu.au/~{jzaragoza,tjchin}
%
% The program is free for non-commercial academic use. Any commercial use
% is strictly prohibited without the authors' consent. Please acknowledge
% the authors by citing the above paper in any academic publications that
% have made use of this package or part of it.
%
% If you encounter any problems or questions please email to
% jzaragoza@cs.adelaide.edu.au.
%
% This program makes use of Peter Kovesi and Andrew Zisserman's MATLAB
% functions for multi-view geometry.
% (http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/
% http://www.robots.ox.ac.uk/~vgg/hzbook/code/).
%
% This program also makes use of Tat-Jun Chin's code for Accelerated
% Hypothesis Generation for Multi-Structure Robust Fitting.
%
% We make use of eigen3's SVD decomposition (in our experience, it is
% faster than MATLAB's SVD).
close all;
clear all;
clc;
%-------
% Paths.
%-------
addpath('modelspecific');
addpath('mexfiles');
addpath('multigs');
%-------------------
% Compile Mex files.
%-------------------
cd multigs;
if exist('computeIntersection','file')~=3
mex computeIntersection.c; % <-- for multigs
end
cd ..;
cd mexfiles;
if exist('imagewarping','file')~=3
mex ../imagewarping.cpp;
end
if exist('wsvd','file')~=3
mex ../wsvd.cpp; % We make use of eigen3's SVD in this file.
end
cd ..;
%----------------------
% Setup VLFeat toolbox.
%----------------------
cd vlfeat-0.9.14/toolbox;
feval('vl_setup');
cd ../..;
%---------------------------------------------
% Check if we are already running in parallel.
%---------------------------------------------
%poolsize = matlabpool('size');
%if poolsize == 0 %if not, we attempt to do it:
% matlabpool open;
%1end
%-------------------------
% User defined parameters.
%-------------------------
% Global model specific function handlers.
clear global;
global fitfn resfn degenfn psize numpar
fitfn = 'homography_fit';
resfn = 'homography_res';
degenfn = 'homography_degen';
psize = 4;
numpar = 9;
M = 500; % Number of hypotheses for RANSAC.
thr = 0.1; % RANSAC threshold.
C1 = 100; % Resolution/grid-size for the mapping function in MDLT (C1 x C2).
C2 = 100;
%if input('Which images you want to stitch? [1 for ''temple''] [2 for ''railtracks''] ') == 1
% fprintf('> Stitching ''temple'' images\n');
% In this implementation the weights are not calculated in the normalised
% space (but in the image space), therefore, these 2 following paramaters
% must be tuned in each case.
% If somebody wants to contribute to this code and calculate the weights in
% the normalised space so that the implementation is not too parameter-dependent,
% please, write me an email (jzaragoza@cs.adelaide.edu.au) and I'll be happy
% to talk with you :)
% gamma = 0.01; % Normalizer for Moving DLT. (0.0015-0.1 are usually good numbers).
% sigma = 8.5; % Bandwidth for Moving DLT. (Between 8-12 are good numbers).
% Load images and SIFT matches for temple data.
% load 'SIFTdata/temple.mat'
%else
% fprintf('> Stitching ''railtracks'' images\n');
% gamma = 0.0015;
% sigma = 12;
% Load images and SIFT matches for railtracks data.
% load 'SIFTdata/railtracks.mat'
%end
%%%%%%%%%%%%%%%%%%%
% *** IMPORTANT ***
%%%%%%%%%%%%%%%%%%%
% If you want to try with your own images and make use of the VLFEAT
% library for SIFT keypoint detection and matching, **comment** the
% previous IF/ELSE STATEMENT and **uncomment** the following code:
%
gamma = 0.1; % Normalizer for Moving DLT. (0.0015-0.1 are usually good numbers).
sigma = 8.5; % Bandwidth for Moving DLT. (Between 8-12 are good numbers).
scale = 1; % Scale of input images (maybe for large images you would like to use a smaller scale).
%
% %------------------
% % Images to stitch.
% %------------------
%change code to blend ten pictures
path1 = 'images/waterfall/1.JPG';
path2 = 'images/waterfall/2.JPG';
path3 = 'images/waterfall/3.JPG';
path4 = 'images/waterfall/4.JPG';
path5 = 'images/waterfall/5.JPG';
path6 = 'images/waterfall/6.JPG';
path7 = 'images/waterfall/7.JPG';
path8 = 'images/waterfall/8.JPG';
%
% %-------------
% % Read images.
% %-------------
fprintf('Read images and SIFT matching\n');tic;
fprintf('> Reading images...');tic;
img1 = imresize(imread(sprintf('%s',path1)),scale);
img2 = imresize(imread(sprintf('%s',path2)),scale);
img3 = imresize(imread(sprintf('%s',path3)),scale);
img4 = imresize(imread(sprintf('%s',path4)),scal