Code covered by the BSD License  

Highlights from
Objects/Faces Detection Toolbox

image thumbnail
from Objects/Faces Detection Toolbox by Sebastien PARIS
Objects/Faces detection using Local Binary Patterns and Haar features

merge_detect(pos , param)
function drect = merge_detect(pos , param)

% load Itest1
% param.overlap1 = 1/2;  %overlap for the same size windows
% param.overlap2 = 1/2;  %overlap for the different size windows
% param.step     = 0.8;
% drect          = merge_detect(pos , param)
% figure(1)
% imagesc(Itest);
% colormap(gray)
% hold on
% plot_rectangle(pos)
% hold off
% figure(2)
% imagesc(Itest);
% colormap(gray)
% hold on
% plot_rectangle(drect)
% hold off
%
% load Itest2
%  load('model_detector_haar_24x24.mat');
% model.postprocessing        = 2;
% min_detect                  = 2;
% model.cascade               = [1 , 2 , 3 , 4 , 10 , 20 , 30 , 30 ; -0.75 ,-0.6 , -0.5, -0.25,  0 ,  0 , 0 , 0];
% model.scalingbox            = [2 , 1.35 , 1.75];
% model.mergingbox            = [1/2 , 1/2 , 0.8];
% param.overlap1              = 1/2;  %overlap for the same size windows
% param.overlap2              = 1/2;  %overlap for the different size windows
% param.step                  = 0.8;
% drect                       = merge_detect(pos , param)
% drect1                      = detector_haar(Itest ,model);
%


[d , nraw]  = size(pos);

if(nargin < 2)  
    param.overlap1 = 1/2;
    param.overlap2 = 1/2;
    param.step     = 0.8;
end

%% Merge detections with equal size and 25 % overlap or more %%

for i = 1 : nraw - 1
    current_sizewindow  = pos(3,i);
    current_stepwindow  = round(current_sizewindow*param.overlap1);
    
    Xinf                = pos(2,i) - current_stepwindow;
    Xsup                = pos(2,i) + current_stepwindow;
    
    Yinf                = pos(1,i) - current_stepwindow;
    Ysup                = pos(1,i) + current_stepwindow;
    
    for j = i+1 : nraw
        if( (current_sizewindow==pos(3,j)) && (Xinf < pos(2,j)) && (Xsup >= pos(2,j)) && (Yinf < pos(1,j)) && (Ysup >= pos(1,j)) )            
            nb_detect                 = pos(4,i) + 0;
            nb_detect1                = nb_detect + 1.0;
            pos(1,j)                  = round((nb_detect*pos(1,i) + pos(1,j))/nb_detect1);
            pos(2,j)                  = round((nb_detect*pos(2,i) + pos(2,j))/nb_detect1);
            pos(4,j)                  = nb_detect1;
            pos(4,i)                  = 0.0;
            break;
        end
    end
end
		
%% Merge overlapping detections of different size %%		
		
[val , ind] = sort(pos(3 , :) , 'descend');

for i = 1 : nraw - 1
    indi = ind(i);
    if(pos(4,indi))
        tmp      = round((pos(3,indi) - 0)*param.overlap2);
        Xsup     = pos(2,indi) + tmp;
        Ysup     = pos(1,indi) + tmp;
        dist_ini = pos(3,indi)*param.step;
        
        for j    = i+1 : nraw
            indj = ind(j);
            if(pos(4,indj))
                current_sizewindow  = ((pos(3,indj) - 0)*param.overlap2);
                tempx               = Xsup - (pos(2,indj) + current_sizewindow);
                tempy               = Ysup - (pos(1,indj) + current_sizewindow);
                if(sqrt(tempx*tempx + tempy*tempy) <= dist_ini)
%                     nb_detect       = pos(4,i);
%                     nb_detect1      = pos(4,j);
%                     
%                     nb_detect_total = nb_detect + nb_detect1;
%                     
%                     pos(1 , j)      = round((nb_detect*pos(1 , i) + nb_detect1*pos(1 , j))/nb_detect_total);
%                     pos(2 , j)      = round((nb_detect*pos(2 , i) + nb_detect1*pos(2 , j))/nb_detect_total);
%                     pos(3 , j)      = round((nb_detect*pos(3 , i) + nb_detect1*pos(3 , j))/nb_detect_total);
%                     pos(5 , j)      = (nb_detect*pos(5 , i) + nb_detect1*pos(5 , j))/nb_detect_total;
%                     
%                     pos(4,j)        = nb_detect_total;
%                     pos(4,i)        = 0.0;
                    
                    
                    nb_detect        = pos(4,indi);
%                     nb_detect1       = pos(4,j);
%                     
%                     nb_detect_total  = nb_detect + nb_detect1;
                    
                    pos([1,2,3,5],indj) = pos([1,2,3,5],indi);
                    
%                     pos(1 , j)      = round((nb_detect*pos(1 , i) + nb_detect1*pos(1 , j))/nb_detect_total);
%                     pos(2 , j)      = round((nb_detect*pos(2 , i) + nb_detect1*pos(2 , j))/nb_detect_total);
%                     pos(3 , j)      = round((nb_detect*pos(3 , i) + nb_detect1*pos(3 , j))/nb_detect_total);
%                     pos(5 , j)      = (nb_detect*pos(5 , i) + nb_detect1*pos(5 , j))/nb_detect_total;
                    
                    pos(4,indj)        = 0.0;
                    pos(4,indi)        = nb_detect + 1;
                   
                    
                    
                    break;
                end
            end
        end
    end
end


ind   = find(pos(4 , :));

drect = pos(: , ind);

Contact us at files@mathworks.com