1

我正在開發用於檢測人員的視頻監視應用程序。目前我正在執行HOG描述符作爲檢測器。但是,我有一個關於滑動窗口技術的問題。我的代碼只能檢測到單個人。我還使用MexOpen CV中的組矩形創建多個邊界框。任何人都有想法如何編寫滑動窗口技術來檢測多個對象?謝謝。用於多人檢測的滑動窗口技術

 % Reading the image 
     im = strcat ('C:\Users\Documents\MATLAB\HOG\HOG\images\16.bmp'); 
     im = imread (im); 

     win_size= [64, 128]; 

     [lastRightCol lastRightRow d] = size(im); 

     counter = 1; 
     %% Scan the window by using sliding window object detection 

     % this for loop scan the entire image and extract features for each sliding window 
     % Loop on scales (based on size of the window) 
     for s=1:0.5:3 
      disp(strcat('s is',num2str(s))); 
      X=win_size(1)*s; 
      Y=win_size(2)*s; 
      for y = 1:X/4:lastRightCol-Y 
       for x = 1:Y/4:lastRightRow-X 
        p1 = [x,y]; 
        p2 = [x+(X-1), y+(Y-1)]; 
        po = [p1; p2] ; 

        % Croped image and scan it. 
        crop_px = [po(1,1) po(2,1)]; 
        crop_py = [po(1,2) po(2,2)]; 

        topLeftRow = ceil(min(crop_px)); 
        topLeftCol = ceil(min(crop_py)); 

        bottomRightRow = ceil(max(crop_px)); 
        bottomRightCol = ceil(max(crop_py)); 

        cropedImage = img(topLeftCol:bottomRightCol,topLeftRow:bottomRightRow,:); 

        % Get the feature vector from croped image using HOG descriptor 
        featureVector{counter} = getHOGDescriptor(img); 
        boxPoint{counter} = [x,y,X,Y]; 
        count = counter+1; 
        x = x+2; 
       end 
      end 
     end 

     label = ones(length(featureVector),1); 
     P = cell2mat(featureVector); 

     % each row of P' correspond to a window 
     % classifying each window 
     [~, predictions] = svmclassify(P', label,model); 


     % set the threshold for getting multiple detection 
     % the threshold value is 0.7 
     get_detect = predictions.*[predictions>0.6]; 

     % the the value after sorted 
     [r,c,v]= find(get_detect); 


     %% Creating the bounding box for detection 
     for ix=1:length(r) 
      rects{ix}= boxPoint{r(ix)}; 
     end 

     if (isempty(rects)) 
      rects2=[]; 
     else 
      rects2 = cv.groupRectangles(rects,3,'EPS',0.35); 
     end 



     for i = 1:numel(rects2) 
      rectangle('Position',[rects2{i}(1),rects2{i}(2),64,128], 'LineWidth',2,'EdgeColor','y'); 
     end 

    end 
+0

請問您可以創建一個mcve。看到這個幫助:http://stackoverflow.com/help/mcve – kkuilla

+0

噢抱歉,我忘記附上我的代碼。這裏我附上了上面的代碼。 @kkuilla,希望你能幫助我。謝謝 – Indrasyach

+0

測試圖像在哪裏?您還應該添加'computer-vision'標籤。你使用函數getHOGDescriptor()。你沒有提到你正在使用哪一個。至少有兩個你可以下載。 – kkuilla

回答

0

計算機視覺系統工具箱包括vision.PeopleDetector對象,它使用一個滑動窗口生豬SVM算法。

+0

感謝您的建議。但是,對於我的項目,我不允許使用任何MATLAB工具箱。我必須建立自己的代碼。因此,在這裏我發現了對多人檢測進行滑動窗口檢測的困難。 @Dima – Indrasyach

0

我不確定您是否正確測試模型。 Here你有一個完整的例子,這是滑動窗口的主要代碼:

topLeftRow = 1; 
topLeftCol = 1; 
[bottomRightCol bottomRightRow d] = size(im); 

fcount = 1; 

% this for loop scan the entire image and extract features for each sliding window 
for y = topLeftCol:bottomRightCol-wSize(2) 
    for x = topLeftRow:bottomRightRow-wSize(1) 
     p1 = [x,y]; 
     p2 = [x+(wSize(1)-1), y+(wSize(2)-1)]; 
     po = [p1; p2]; 
     img = imcut(po,im);  
     featureVector{fcount} = HOG(double(img)); 
     boxPoint{fcount} = [x,y]; 
     fcount = fcount+1; 
     x = x+1; 
    end 
end 

lebel = ones(length(featureVector),1); 
P = cell2mat(featureVector); 
% each row of P' correspond to a window 
[~, predictions] = svmclassify(P',lebel,model); % classifying each window 

[a, indx]= max(predictions);