【问题标题】:sliding window technique for multiple people detection用于多人检测的滑动窗口技术
【发布时间】:2014-06-07 18:45:23
【问题描述】:

我正在开发用于检测人员的视频监控应用程序。目前我正在实现 HOG 描述符作为检测器。但是,我对滑动窗口技术有疑问。我的代码只能检测到一个人。我还使用 MexOpen CV 中的 Group Rectangles 来创建多个边界框。有人知道如何编写滑动窗口技术来检测多个对象吗?谢谢。

      % 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

【问题讨论】:

  • 请您创建一个 mcve。看到这个寻求帮助:stackoverflow.com/help/mcve
  • 很抱歉,我忘记附上我的代码。在这里,我附上了上面的代码。 @kkuilla,希望你能帮助我。谢谢
  • 测试图像在哪里?您还应该添加computer-vision 标签。你使用函数getHOGDescriptor().你没有提到你使用的是哪一个。您至少可以下载两个。
  • @kkuilla。我不能在这里写下我所有的代码。会很长。我只想知道我的滑动窗口技术是否正确以检测框架内的多个人。函数getHOGDescriptor(),我从这里发布的某人代码修改:HOG code for Matlab。我正在使用来自 mex opencv 的 Group Rectangles 创建多个边界框。但是,主要问题仍然是滑动窗口检测。希望你能帮助我。谢谢

标签: matlab image-processing computer-vision matlab-cvst sliding-window


【解决方案1】:

计算机视觉系统工具箱包含vision.PeopleDetector 对象,该对象使用滑动窗口HoG-SVM 算法。

【讨论】:

  • 感谢您的建议。但是,对于我的项目,我不允许使用任何 MATLAB 工具箱。我必须构建自己的代码。因此,在这里我发现为多人检测进行滑动窗口检测有任何困难。 @Dima
【解决方案2】:

我不确定您是否正确地测试了模型。 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);

【讨论】:

    猜你喜欢
    • 2018-07-23
    • 2011-08-28
    • 1970-01-01
    • 2011-02-08
    • 1970-01-01
    • 2016-10-31
    • 2017-01-11
    • 2017-12-20
    • 1970-01-01
    相关资源
    最近更新 更多