如何在滑动窗口检测中实现积分图像?

时间:2014-08-11 06:51:34

标签: matlab image-processing computer-vision object-detection matlab-cvst

我正在做一个使用HOG-LBP检测人群中的人的项目。我想把它用于实时应用。我已经读过一些参考文献,积分图像/直方图可以提高滑动窗口检测的性能速度。我想问一下,如何在我的滑动窗口检测中实现积分图像:

这是来自matlab的积分图像代码:

A = (cumsum(cumsum(double(img)),2));

这里是我的滑动窗口检测代码:

im = strcat ('C:\Documents\Crowd_PETS09\S1\L1\Time_13-57\View_001\frame_0150.jpg');
im = imread (im);


figure (1), imshow(im);

win_size= [32, 32];

[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
    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

            %get four points for boxes
            p1  = [x,y];
            p2  = [x+(X-1), y+(Y-1)];
            po  = [p1; p2] ;

            % cropped image based on the four points
            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    = im(topLeftCol:bottomRightCol,topLeftRow:bottomRightRow,:);

            %Get the feature vector from croped image
            HOGfeatureVector{counter}= getHOG(double(cropedImage));
            LBPfeatureVector{counter}= getLBP(cropedImage);
            LBPfeatureVector{counter}= LBPfeatureVector{counter}';
            boxPoint{counter} = [x,y,X,Y];
            counter = counter+1;
            x = x+2;

        end
    end
end

我应该把积分图像代码放在哪里?

我真的很感激,如果有人能帮我解决这个问题。

谢谢。

1 个答案:

答案 0 :(得分:1)

积分图像最适合类Haar特征。将它用于HOG或LBP将是棘手的。我建议首先让你的算法工作,然后考虑优化它。

顺便说一句,计算机视觉系统工具箱包含extractHOGFeatures功能,这将有所帮助。这是example of training a HOG-SVM classifier to recognize hand-written digits。还有一个vision.PeopleDetector对象,它使用HOG-SVM分类器来检测人。您可以直接将它用于项目,也可以用它来评估自己算法的性能。