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

0 投票
1 回答
3059 浏览
提问于 2025-04-18 06:48

我写了一个分类器,现在想用它来检测图片。我的分类器已经有了一些我感兴趣的物体的HoG特征模型。现在我已经实现了滑动窗口的功能,这个窗口会在不同的尺度上滑动过图片,我也能为每个窗口提取HoG特征。

我想问的是,接下来该怎么做?

这真的就像把模型的HoG特征和窗口提取的特征进行匹配那么简单吗?我知道,对于每个类别(比如人脸不是人脸),使用积分图像时有一个阈值。如果窗口生成的图像计算出的值和这个类别的值足够接近,并且没有超过阈值,那我们就可以说匹配成功了。

但是,HoG特征是怎么工作的呢?

1 个回答

3

没错,就是这么简单。一旦你有了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来检测对象出现的窗口。

撰写回答