实现滑动窗口分类器HoG特征检测



我已经编写了一个分类器,现在要应用它来检测图像。我的分类器已经有了一些我感兴趣的对象的HoG特征的模型。我有滑动窗口的功能,它也会在不同比例的图像上滑动,我可以得到每个窗口的HoG特征。我的问题是,下一步怎么办?

它真的像匹配模型的HoG特征和来自窗口的特征一样简单吗?我明白,对于积分图像,每个类(如facenot face)都有一个阈值,如果窗口生成图像的计算值足够接近类的值并且不超过阈值,那么我们说我们已经得到了匹配。

但是它如何与HoG功能一起工作呢?

是的,就是这么简单。一旦您有了HOG模型和窗口,您只需要将窗口特性应用到模型上。然后选择最佳结果(是否使用阈值,取决于您的应用程序)。

这里有一个执行相同步骤的示例代码。关键部分如下:

function detect(im,model,wSize)
   %{
   this function will take three parameters
    1.  im      --> Test Image
    2.  model   --> trained model
    3.  wStize  --> Size of the window, i.e. [24,32]
   and draw rectangle on best estimated window
   %}
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);
bBox = cell2mat(boxPoint(indx));
rectangle('Position',[bBox(1),bBox(2),24,32],'LineWidth',1, 'EdgeColor','r');
end

对于每个窗口,代码提取HOG描述符并将其存储在featureVector中。然后使用svmclassify,代码检测对象所在的窗口。

最新更新