APAP调试代码_udp调试工具

APAP调试代码_udp调试工具用来调试的matlab代码%————————————————————————-%As-Projective-As-PossibleImageStitchingwithMovingDLT%(PatentPending)

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

用来调试的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)),scale);
 img5 = imresize(imread(sprintf('%s',path5)),scale);
 img6 = imresize(imread(sprintf('%s',path6)),scale);
 img7 = imresize(imread(sprintf('%s',path7)),scale);
 img8 = imresize(imread(sprintf('%s',path8)),scale);

 fprintf('done (%fs)\n',toc);
% 
% %--------------------------------------
% % SIFT keypoint detection and matching.
% %--------------------------------------
 fprintf(' Keypoint detection and matching...');tic;
 [ kp1,ds1 ] = vl_sift(single(rgb2gray(img1)),'PeakThresh', 0,'edgethresh',500);
 [ kp2,ds2 ] = vl_sift(single(rgb2gray(img2)),'PeakThresh', 0,'edgethresh',500);
 [ kp3,ds3 ] = vl_sift(single(rgb2gray(img3)),'PeakThresh', 0,'edgethresh',500);
 [ kp4,ds4 ] = vl_sift(single(rgb2gray(img4)),'PeakThresh', 0,'edgethresh',500);
 [ kp5,ds5 ] = vl_sift(single(rgb2gray(img5)),'PeakThresh', 0,'edgethresh',500);
 [ kp6,ds6 ] = vl_sift(single(rgb2gray(img6)),'PeakThresh', 0,'edgethresh',500);
 [ kp7,ds7 ] = vl_sift(single(rgb2gray(img7)),'PeakThresh', 0,'edgethresh',500);
 [ kp8,ds8 ] = vl_sift(single(rgb2gray(img8)),'PeakThresh', 0,'edgethresh',500);
 matches_1  = vl_ubcmatch(ds1,ds2);
 matches_2  = vl_ubcmatch(ds1,ds3);
 matches_3  = vl_ubcmatch(ds1,ds4);
 matches_4  = vl_ubcmatch(ds1,ds5);
 matches_5  = vl_ubcmatch(ds1,ds6);
 matches_6  = vl_ubcmatch(ds1,ds7);
 matches_7  = vl_ubcmatch(ds1,ds8);
 %matches_8 = vl_ubcmatch(ds1,ds2);
 fprintf('done (%fs)\n',toc);

% Normalise point distribution.
fprintf(' Normalising point distribution...');tic;
data_orig_1 = [ kp1(1:2,matches_1(1,:)) ; ones(1,size(matches_1,2)) ; kp2(1:2,matches_1(2,:)) ; ones(1,size(matches_1,2)) ];
data_orig_2 = [ kp1(1:2,matches_2(1,:)) ; ones(1,size(matches_2,2)) ; kp3(1:2,matches_2(2,:)) ; ones(1,size(matches_2,2)) ];
data_orig_3 = [ kp1(1:2,matches_3(1,:)) ; ones(1,size(matches_3,2)) ; kp4(1:2,matches_3(2,:)) ; ones(1,size(matches_3,2)) ];
data_orig_4 = [ kp1(1:2,matches_4(1,:)) ; ones(1,size(matches_4,2)) ; kp5(1:2,matches_4(2,:)) ; ones(1,size(matches_4,2)) ];
data_orig_5 = [ kp1(1:2,matches_5(1,:)) ; ones(1,size(matches_5,2)) ; kp6(1:2,matches_5(2,:)) ; ones(1,size(matches_5,2)) ];
data_orig_6 = [ kp1(1:2,matches_6(1,:)) ; ones(1,size(matches_6,2)) ; kp7(1:2,matches_6(2,:)) ; ones(1,size(matches_6,2)) ];
data_orig_7 = [ kp1(1:2,matches_7(1,:)) ; ones(1,size(matches_7,2)) ; kp8(1:2,matches_7(2,:)) ; ones(1,size(matches_7,2)) ];
%data_orig_8 = [ kp1(1:2,matches_1(1,:)) ; ones(1,size(matches_1,2)) ; kp2(1:2,matches_1(2,:)) ; ones(1,size(matches_1,2)) ];
[ dat_1_norm_img1,T_1_1 ] = normalise2dpts(data_orig_1(1:3,:));
[ dat_1_norm_img2,T_1_2 ] = normalise2dpts(data_orig_1(4:6,:));
[ dat_2_norm_img1,T_2_1 ] = normalise2dpts(data_orig_2(1:3,:));
[ dat_2_norm_img2,T_2_2 ] = normalise2dpts(data_orig_2(4:6,:));
[ dat_3_norm_img1,T_3_1 ] = normalise2dpts(data_orig_3(1:3,:));
[ dat_3_norm_img2,T_3_2 ] = normalise2dpts(data_orig_3(4:6,:));
[ dat_4_norm_img1,T_4_1 ] = normalise2dpts(data_orig_4(1:3,:));
[ dat_4_norm_img2,T_4_2 ] = normalise2dpts(data_orig_4(4:6,:));
[ dat_5_norm_img1,T_5_1 ] = normalise2dpts(data_orig_5(1:3,:));
[ dat_5_norm_img2,T_5_2 ] = normalise2dpts(data_orig_5(4:6,:));
[ dat_6_norm_img1,T_6_1 ] = normalise2dpts(data_orig_6(1:3,:));
[ dat_6_norm_img2,T_6_2 ] = normalise2dpts(data_orig_6(4:6,:));
[ dat_7_norm_img1,T_7_1 ] = normalise2dpts(data_orig_7(1:3,:));
[ dat_7_norm_img2,T_7_2 ] = normalise2dpts(data_orig_7(4:6,:));
data_norm_1 = [ dat_1_norm_img1 ; dat_1_norm_img2 ];
data_norm_2 = [ dat_2_norm_img1 ; dat_2_norm_img2 ];
data_norm_3 = [ dat_3_norm_img1 ; dat_3_norm_img2 ];
data_norm_4 = [ dat_4_norm_img1 ; dat_4_norm_img2 ];
data_norm_5 = [ dat_5_norm_img1 ; dat_5_norm_img2 ];
data_norm_6 = [ dat_6_norm_img1 ; dat_6_norm_img2 ];
data_norm_7 = [ dat_7_norm_img1 ; dat_7_norm_img2 ];

fprintf('done (%fs)\n',toc);

if size(img1,1) == size(img2,1)    
    % Show input images.
    fprintf(' Showing input images...');tic;
    figure;
    imshow([img1,img2]);
    title('Input images');
    fprintf('done (%fs)\n',toc);
end

%-----------------
% Outlier removal.
%-----------------
fprintf('Outlier removal\n');tic;
% Multi-GS
rng(0);
[ ~,res_1,~,~ ] = multigsSampling(100,data_norm_1,M,10);
[ ~,res_2,~,~ ] = multigsSampling(100,data_norm_2,M,10);
[ ~,res_3,~,~ ] = multigsSampling(100,data_norm_3,M,10);
[ ~,res_4,~,~ ] = multigsSampling(100,data_norm_4,M,10);
[ ~,res_5,~,~ ] = multigsSampling(100,data_norm_5,M,10);
[ ~,res_6,~,~ ] = multigsSampling(100,data_norm_6,M,10);
[ ~,res_7,~,~ ] = multigsSampling(100,data_norm_7,M,10);

con_1 = sum(res_1<=thr);
con_2 = sum(res_2<=thr);
con_3 = sum(res_3<=thr);
con_4 = sum(res_4<=thr);
con_5 = sum(res_5<=thr);
con_6 = sum(res_6<=thr);
con_7 = sum(res_7<=thr);

[ ~, maxinx_1 ] = max(con_1);
[ ~, maxinx_2 ] = max(con_2);
[ ~, maxinx_3 ] = max(con_3);
[ ~, maxinx_4 ] = max(con_4);
[ ~, maxinx_5 ] = max(con_5);
[ ~, maxinx_6 ] = max(con_6);
[ ~, maxinx_7 ] = max(con_7);

inliers_1 = find(res_1(:,maxinx_1)<=thr);
inliers_2 = find(res_2(:,maxinx_2)<=thr);
inliers_3 = find(res_3(:,maxinx_3)<=thr);
inliers_4 = find(res_4(:,maxinx_4)<=thr);
inliers_5 = find(res_5(:,maxinx_5)<=thr);
inliers_6 = find(res_6(:,maxinx_6)<=thr);
inliers_7 = find(res_7(:,maxinx_7)<=thr);

%{ 
   
if size(img1,1) == size(img2,1)
    % Show results of RANSAC.
    fprintf(' Showing results of RANSAC...');tic;
    figure;
    imshow([img1 img2]);
    hold on;
    plot(data_orig_1(1,:),data_orig_1(2,:),'ro','LineWidth',2);
    plot(data_orig_1(4,:)+size(img1,2),data_orig_1(5,:),'ro','LineWidth',2);
    for i=1:length(inliers)
        plot(data_orig_1(1,inliers(i)),data_orig_1(2,inliers(i)),'go','LineWidth',2);
        plot(data_orig_1(4,inliers(i))+size(img1,2),data_orig_1(5,inliers(i)),'go','LineWidth',2);
        plot([data_orig_1(1,inliers(i)) data_orig_1(4,inliers(i))+size(img1,2)],[data_orig_1(2,inliers(i)) data_orig_1(5,inliers(i))],'g-');
    end
    title('Ransac''s results');
    fprintf('done (%fs)\n',toc);
end
%}
%-----------------------
% Global homography (H).
%-----------------------
fprintf('DLT (projective transform) on inliers\n');
% Refine homography using DLT on inliers.
fprintf('> Refining homography (H) using DLT...');tic;
[ h_1,A_1,D_1_1,D_1_2 ] = feval(fitfn,data_norm_1(:,inliers_1));
[ h_2,A_2,D_2_1,D_2_2 ] = feval(fitfn,data_norm_2(:,inliers_2));
[ h_3,A_3,D_3_1,D_3_2 ] = feval(fitfn,data_norm_3(:,inliers_3));
[ h_4,A_4,D_4_1,D_4_2 ] = feval(fitfn,data_norm_4(:,inliers_4));
[ h_5,A_5,D_5_1,D_5_2 ] = feval(fitfn,data_norm_5(:,inliers_5));
[ h_6,A_6,D_6_1,D_6_2 ] = feval(fitfn,data_norm_6(:,inliers_6));
[ h_7,A_7,D_7_1,D_7_2 ] = feval(fitfn,data_norm_7(:,inliers_7));

Hg_1 = T_1_2\(reshape(h_1,3,3)*T_1_1);
Hg_2 = T_2_2\(reshape(h_2,3,3)*T_2_1);
Hg_3 = T_3_2\(reshape(h_3,3,3)*T_3_1);
Hg_4 = T_4_2\(reshape(h_4,3,3)*T_4_1);
Hg_5 = T_5_2\(reshape(h_5,3,3)*T_5_1);
Hg_6 = T_6_2\(reshape(h_6,3,3)*T_6_1);
Hg_7 = T_7_2\(reshape(h_7,3,3)*T_7_1);

fprintf('done (%fs)\n',toc);

%----------------------------------------------------
% Obtaining size of canvas (using global Homography).
%----------------------------------------------------
fprintf('Canvas size and offset (using global Homography)\n');
fprintf('> Getting canvas size...');tic;
% Map four corners of the right image.
TL_1 = Hg_1\[1;1;1];
TL_1 = round([ TL_1(1)/TL_1(3) ; TL_1(2)/TL_1(3) ]);
BL_1 = Hg_1\[1;size(img2,1);1];
BL_1 = round([ BL_1(1)/BL_1(3) ; BL_1(2)/BL_1(3) ]);
TR_1 = Hg_1\[size(img2,2);1;1];
TR_1 = round([ TR_1(1)/TR_1(3) ; TR_1(2)/TR_1(3) ]);
BR_1 = Hg_1\[size(img2,2);size(img2,1);1];
BR_1 = round([ BR_1(1)/BR_1(3) ; BR_1(2)/BR_1(3) ]);

TL_2 = Hg_2\[1;1;1];
TL_2 = round([ TL_2(1)/TL_2(3) ; TL_2(2)/TL_2(3) ]);
BL_2 = Hg_2\[1;size(img3,1);1];
BL_2 = round([ BL_2(1)/BL_2(3) ; BL_2(2)/BL_2(3) ]);
TR_2 = Hg_2\[size(img3,2);1;1];
TR_2 = round([ TR_2(1)/TR_2(3) ; TR_2(2)/TR_2(3) ]);
BR_2 = Hg_2\[size(img3,2);size(img3,1);1];
BR_2 = round([ BR_2(1)/BR_2(3) ; BR_2(2)/BR_2(3) ]);

TL_3 = Hg_3\[1;1;1];
TL_3 = round([ TL_3(1)/TL_3(3) ; TL_3(2)/TL_3(3) ]);
BL_3 = Hg_3\[1;size(img4,1);1];
BL_3 = round([ BL_3(1)/BL_3(3) ; BL_3(2)/BL_3(3) ]);
TR_3 = Hg_3\[size(img4,2);1;1];
TR_3 = round([ TR_3(1)/TR_3(3) ; TR_3(2)/TR_3(3) ]);
BR_3 = Hg_3\[size(img4,2);size(img4,1);1];
BR_3 = round([ BR_3(1)/BR_3(3) ; BR_3(2)/BR_3(3) ]);

TL_4 = Hg_4\[1;1;1];
TL_4 = round([ TL_4(1)/TL_4(3) ; TL_4(2)/TL_4(3) ]);
BL_4 = Hg_4\[1;size(img5,1);1];
BL_4 = round([ BL_4(1)/BL_4(3) ; BL_4(2)/BL_4(3) ]);
TR_4 = Hg_4\[size(img5,2);1;1];
TR_4 = round([ TR_4(1)/TR_4(3) ; TR_4(2)/TR_4(3) ]);
BR_4 = Hg_4\[size(img5,2);size(img5,1);1];
BR_4 = round([ BR_4(1)/BR_4(3) ; BR_4(2)/BR_4(3) ]);
% Canvas size.
%cw = max([1 size(img1,2) TL_1(1) BL_1(1) TR_1(1) BR_1(1) TL_2(1) BL_2(1) TR_2(1) BR_2(1) TL_3(1) BL_3(1) TR_3(1) BR_3(1) TL_4(1) BL_4(1) TR_4(1) BR_4(1)]) - min([1 size(img1,2) TL_1(1) BL_1(1) TR_1(1) BR_1(1) TL_2(1) BL_2(1) TR_2(1) BR_2(1) TL_3(1) BL_3(1) TR_3(1) BR_3(1) TL_4(1) BL_4(1) TR_4(1) BR_4(1)]) + 1;
%ch = max([1 size(img1,1) TL_1(2) BL_1(2) TR_1(2) BR_1(2) TL_2(2) BL_2(2) TR_2(2) BR_2(2) TL_3(2) BL_3(2) TR_3(2) BR_3(2) TL_4(2) BL_4(2) TR_4(2) BR_4(2)]) - min([1 size(img1,1) TL_1(2) BL_1(2) TR_1(2) BR_1(2) TL_2(2) BL_2(2) TR_2(2) BR_2(2) TL_3(2) BL_3(2) TR_3(2) BR_3(2) TL_4(2) BL_4(2) TR_4(2) BR_4(2)]) + 1;
cw = max([1 size(img1,2) TL_1(1) BL_1(1) TR_1(1) BR_1(1) TL_2(1) BL_2(1) TR_2(1) BR_2(1)]) - min([1 size(img1,2) TL_1(1) BL_1(1) TR_1(1) BR_1(1) TL_2(1) BL_2(1) TR_2(1) BR_2(1)]) + 1;
ch = max([1 size(img1,1) TL_1(2) BL_1(2) TR_1(2) BR_1(2) TL_2(2) BL_2(2) TR_2(2) BR_2(2)]) - min([1 size(img1,1) TL_1(2) BL_1(2) TR_1(2) BR_1(2) TL_2(2) BL_2(2) TR_2(2) BR_2(2)]) + 1;
%cw = max([1 size(img1,2) TL_1(1) BL_1(1) TR_1(1) BR_1(1)]) - min([1 size(img1,2) TL_1(1) BL_1(1) TR_1(1) BR_1(1)]) + 1;
%ch = max([1 size(img1,1) TL_1(2) BL_1(2) TR_1(2) BR_1(2)]) - min([1 size(img1,1) TL_1(2) BL_1(2) TR_1(2) BR_1(2)]) + 1;
fprintf('done (%fs)\n',toc);

% Offset for left image.
fprintf('> Getting offset...');tic;
%off = [ 1 - min([1 size(img1,2) TL_1(1) BL_1(1) TR_1(1) BR_1(1) TL_2(1) BL_2(1) TR_2(1) BR_2(1) TL_3(1) BL_3(1) TR_3(1) BR_3(1) TL_4(1) BL_4(1) TR_4(1) BR_4(1)]) + 1 ; 1 - min([1 size(img1,1) TL_1(2) BL_1(2) TR_1(2) BR_1(2) TL_2(2) BL_2(2) TR_2(2) BR_2(2) TL_3(2) BL_3(2) TR_3(2) BR_3(2) TL_4(2) BL_4(2) TR_4(2) BR_4(2)]) + 1 ];
off = [ 1 - min([1 size(img1,2) TL_1(1) BL_1(1) TR_1(1) BR_1(1) TL_2(1) BL_2(1) TR_2(1) BR_2(1)]) + 1 ; 1 - min([1 size(img1,1) TL_1(2) BL_1(2) TR_1(2) BR_1(2) TL_2(2) BL_2(2) TR_2(2) BR_2(2)]) + 1 ];
%off = [ 1 - min([1 size(img1,2) TL_1(1) BL_1(1) TR_1(1) BR_1(1)]) + 1 ; 1 - min([1 size(img1,1) TL_1(2) BL_1(2) TR_1(2) BR_1(2) TL_2(2) BL_2(2) TR_2(2) BR_2(2)]) + 1 ];
fprintf('done (%fs)\n',toc);

%--------------------------------------------
% Image stitching with global homography (H).
%--------------------------------------------
% Warping source image with global homography 
fprintf('Image stitching with global homography (H) and linear blending\n');
fprintf('> Warping images by global homography...');tic;
warped_img1 = uint8(zeros(ch,cw,3));
warped_img1(off(2):(off(2)+size(img1,1)-1),off(1):(off(1)+size(img1,2)-1),:) = img1;
warped_img2 = imagewarping(double(ch),double(cw),double(img2),Hg_1,double(off));
warped_img3 = imagewarping(double(ch),double(cw),double(img3),Hg_2,double(off));
warped_img4 = imagewarping(double(ch),double(cw),double(img4),Hg_3,double(off));
warped_img5 = imagewarping(double(ch),double(cw),double(img5),Hg_4,double(off));

warped_img2 = reshape(uint8(warped_img2),size(warped_img2,1),size(warped_img2,2)/3,3);
warped_img3 = reshape(uint8(warped_img3),size(warped_img3,1),size(warped_img3,2)/3,3);
warped_img4 = reshape(uint8(warped_img4),size(warped_img4,1),size(warped_img4,2)/3,3);
warped_img5 = reshape(uint8(warped_img5),size(warped_img5,1),size(warped_img5,2)/3,3);
fprintf('done (%fs)\n',toc);

% Blending images by simple average (linear blending)
fprintf(' Homography linear image blending (averaging)...');tic;
linear_hom = imageblending(warped_img1,warped_img2,warped_img3,warped_img4,warped_img5);
imwrite(linear_hom, 'linear_hom.jpg')
fprintf('done (%fs)\n',toc);
figure;
imshow(linear_hom);
title('Image Stitching with global homography');

%-------------------------
% Moving DLT (projective).
%-------------------------
fprintf('As-Projective-As-Possible Moving DLT on inliers\n');

% Image keypoints coordinates.
Kp_1 = [data_orig_1(1,inliers_1)' data_orig_1(2,inliers_1)'];
Kp_2 = [data_orig_2(1,inliers_2)' data_orig_2(2,inliers_2)'];
Kp_3 = [data_orig_3(1,inliers_3)' data_orig_3(2,inliers_3)'];
Kp_4 = [data_orig_4(1,inliers_4)' data_orig_4(2,inliers_4)'];


% Generating mesh for MDLT.
fprintf('> Generating mesh for MDLT...');tic;
[ X,Y ] = meshgrid(linspace(1,cw,C1),linspace(1,ch,C2));
fprintf('done (%fs)\n',toc);

% Mesh (cells) vertices' coordinates.
Mv = [X(:)-off(1), Y(:)-off(2)];

% Perform Moving DLT
fprintf(' Moving DLT main loop...');tic;
Hmdlt_1 = zeros(size(Mv,1),9);
Hmdlt_2 = zeros(size(Mv,1),9);
Hmdlt_3 = zeros(size(Mv,1),9);
Hmdlt_4 = zeros(size(Mv,1),9);
parfor i=1:size(Mv,1)

    % Obtain kernel 
    Gki = exp(-pdist2(Mv(i,:),Kp_1)./sigma^2);   

    % Capping/offsetting kernel
    Wi = max(gamma,Gki); 

    % This function receives W and A and obtains the least significant 
    % right singular vector of W*A by means of SVD on WA (Weighted SVD).
    v = wsvd(Wi,A_1);
    %svd(w)
    h_1 = reshape(v,3,3)'; % De-condition h_1 = D_1_2\h_1*D_1_1; % De-normalize h_1 = T_1_2\h_1*T_1_1; Hmdlt_1(i,:) = h_1(:); end parfor i=1:size(Mv,1) % Obtain kernel Gki = exp(-pdist2(Mv(i,:),Kp_2)./sigma^2); % Capping/offsetting kernel Wi = max(gamma,Gki); % This function receives W and A and obtains the least significant % right singular vector of W*A by means of SVD on WA (Weighted SVD). v = wsvd(Wi,A_2); %svd(w) h_2 = reshape(v,3,3)';        

    % De-condition
    h_2 = D_2_2\h_2*D_2_1;

    % De-normalize
    h_2 = T_2_2\h_2*T_2_1;

    Hmdlt_2(i,:) = h_2(:);
end
parfor i=1:size(Mv,1)

    % Obtain kernel 
    Gki = exp(-pdist2(Mv(i,:),Kp_3)./sigma^2);   

    % Capping/offsetting kernel
    Wi = max(gamma,Gki); 

    % This function receives W and A and obtains the least significant 
    % right singular vector of W*A by means of SVD on WA (Weighted SVD).
    v = wsvd(Wi,A_3);
    %svd(w)
    h_3 = reshape(v,3,3)'; % De-condition h_3 = D_3_2\h_3*D_3_1; % De-normalize h_3 = T_3_2\h_3*T_3_1; Hmdlt_3(i,:) = h_3(:); end parfor i=1:size(Mv,1) % Obtain kernel Gki = exp(-pdist2(Mv(i,:),Kp_4)./sigma^2); % Capping/offsetting kernel Wi = max(gamma,Gki); % This function receives W and A and obtains the least significant % right singular vector of W*A by means of SVD on WA (Weighted SVD). v = wsvd(Wi,A_4); %svd(w) h_4 = reshape(v,3,3)';        

    % De-condition
    h_4 = D_4_2\h_4*D_4_1;

    % De-normalize
    h_4 = T_4_2\h_4*T_4_1;

    Hmdlt_4(i,:) = h_4(:);
end
fprintf('done (%fs)\n',toc);

%---------------------------------
% Image stitching with Moving DLT.
%---------------------------------
fprintf('As-Projective-As-Possible Image stitching with Moving DLT and linear blending\n');
% Warping images with Moving DLT.
fprintf('> Warping images with Moving DLT...');tic;
warped_img1 = uint8(zeros(ch,cw,3));
warped_img1(off(2):(off(2)+size(img1,1)-1),off(1):(off(1)+size(img1,2)-1),:) = img1;
[warped_img2] = imagewarping(double(ch),double(cw),double(img2),Hmdlt_1,double(off),X(1,:),Y(:,1)'); warped_img2 = reshape(uint8(warped_img2),size(warped_img2,1),size(warped_img2,2)/3,3); [warped_img3] = imagewarping(double(ch),double(cw),double(img3),Hmdlt_2,double(off),X(1,:),Y(:,1)');
warped_img3 = reshape(uint8(warped_img3),size(warped_img3,1),size(warped_img3,2)/3,3);
[warped_img4] = imagewarping(double(ch),double(cw),double(img4),Hmdlt_3,double(off),X(1,:),Y(:,1)'); warped_img4 = reshape(uint8(warped_img4),size(warped_img4,1),size(warped_img4,2)/3,3); [warped_img5] = imagewarping(double(ch),double(cw),double(img5),Hmdlt_4,double(off),X(1,:),Y(:,1)');
warped_img5 = reshape(uint8(warped_img5),size(warped_img5,1),size(warped_img5,2)/3,3);
fprintf('done (%fs)\n',toc);

% Blending images by averaging (linear blending)
fprintf(' Moving DLT linear image blending (averaging)...');tic;
linear_mdlt = imageblending(warped_img1,warped_img2,warped_img3,warped_img4,warped_img5);
fprintf('done (%fs)\n',toc);
figure;
imshow(linear_mdlt);
title('As-Projective-As-Possible Image Stitching with Moving DLT');
imwrite(linear_mdlt,'linear_mdlt.jpg');
fprintf('> Finished!.\n');
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/190831.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • windows关闭135,139端口_危险端口有哪些

    windows关闭135,139端口_危险端口有哪些我用nmap扫描自己的主机,发现自己的某些端口开启着的,我去了解了一下139端口这个端口比较危险139端口是NetBIOSSession端口,用来文件和打印共享如果你是单机,不是企业内部网里的成员,为了保护计算机的安全关闭这个端口比较好。下面是步骤1开始键输入控制面板点击进入控制面板然后点击进入网络和internet2点击进入网络和共享中心点击进入更改适配器设置在…

    2022年10月17日
  • DB2_自动生成值

    DB2_自动生成值

  • Redis常用命令–set

    Redis常用命令–set

  • 查看linux 定时任务的执行记录

    查看linux 定时任务的执行记录1,查看有哪些任务[root@daping-6~]#crontab-lSHELL=/bin/bashPATH=/sbin:/bin:/usr/sbin:/usr/binMAILTO=root#Fordetailsseeman4crontabs#Exampleofjobdefinition:#.—————-minute(0-59)#|.————-hour(0-23)#||.——-.

    2022年10月27日
  • wxpython入门教程_wxPython 入门教程

    wxpython入门教程_wxPython 入门教程这篇文章是关于wxPython,但wxPython实际是两件事物的组合体:Python脚本语言和GUI功能的wxWindows库(关于wxWindows的介绍,请参阅developerWorks上的“细述wxWindows”)。wxWindows库是为了最大可移植性的C/C++库,而抽取GUI功能。所以wxWindows应用程序与生俱来地可以运行在Win…

  • Linux基础篇——Linux磁盘操作(磁盘基础知识、分类、分区、挂载、卸载、扩容)详解「建议收藏」

    Linux基础篇——Linux磁盘操作(磁盘基础知识、分类、分区、挂载、卸载、扩容)详解「建议收藏」目录1.概念1.概念图1.1分区的概念与好处  假如你有个大木桶要装东西,如果木桶没有划分层,所有东西全部放入里面,虽然可以装,但是对大木桶的使用就合不合理,造成杂乱无章,寻找东西时候也耗时,甚至还有不同物品之间不能存放在一起而导致危险,那更好的做法自然是给大木桶画一下不同的区域,分成不同的层,每个层放不同的东西,即安全,寻找起来也方便;  计算机的磁盘(也叫硬盘)也是如此,为了区分存储内容的不同,以及快速定位寻址文件,也需要采取分区的形式;…

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号