www.gusucode.com > Adaboost算法训练人脸图像和非人脸图像,通过迭代得到由多个弱分类器组合而成的强分类器,实现图片里的人脸检测。 > Adaboost算法训练人脸图像和非人脸图像,通过迭代得到由多个弱分类器组合而成的强分类器,实现图片里的人脸检测。/myfacedet02/Slide.m

    deltax=18; % the shifting by x in each iteration
deltay=27; % the shifting by y in each iteration
XWindowWidth=24; % The size of the moving window
YWindowWidth=24;
%scale=0.2;
 I= imread('IMG_0143_02.jpg'); 
[d1,d2,d3] = size(I); 
if(d3 > 1) 
I = rgb2gray(I);%如果是灰度图就不用先变换 
end 
I1=I;

  %  I1=imresize(I1,scale, 'bilinear');
            figure,imshow(I1);

[ImHeight,ImWidth, ImDepth]=size(I1);
% Here i find the number of subwindows to be extracted from the moving window from all the image
NofXsubWindoes=1+floor((ImWidth-XWindowWidth)/deltax); 
%我明白这里是为什么了
%也就是为什么不是
%ImWidth/deltax
%而是这个形式
NofYsubWindoes=1+floor((ImHeight-YWindowWidth)/deltay);

% Prealocating the the resultant sliding window 
Temp18x27Imgae=(zeros(24,24,NofYsubWindoes*NofXsubWindoes));
TempCounter=1;
updateclass=[];%shi kong er bu shi kong ge

 for y=1:NofYsubWindoes
    for x=1:NofXsubWindoes
    Temp24x24Image(:,:,TempCounter)=I1((deltay*(y-1)+1):deltay*(y-1) +YWindowWidth,(deltax*(x-1)+1):deltax*(x-1)+XWindowWidth);
    Temp24x24=Temp24x24Image(:,:,TempCounter);
    ii=bianli(Temp24x24);
    ii=buzero(ii,1,1);
    myFeature=[];
    F12=tezhen1(ii); %为矩形特征值数组
    F21=tezhen21(ii);
    F31=tezhen31(ii);
    myFeature=[myFeature;F12 F21 F31];
    Newclass=myadaboost_te(adaboost_model,@mythreshold_te,myFeature);

    updateclass=[updateclass,Newclass];
    if Newclass==2
         % rectangle('Position',[x,y,w,h])  
	   % x=(deltay*(y-1)+1)
	   % y=(deltax*(x-1)+1)
	   % w=18
	   % h=27
       hold on;

	   rectangle('Position',[(deltax*(x-1)+1),(deltay*(y-1)+1),24,24],'EdgeColor','r' );
    end
   
	
    
%这里是说什么呢
%应该很容易明白了
%就是将24*24的窗口,在图像上滑动,然后呢,拷贝一下窗口所覆盖区域的像素值
    TempCounter=TempCounter+1; 
    end
 end
 disp('weak_learner_n');
 disp(weak_learner_n);
 disp('updateclass');
 disp(updateclass);