Reputation: 12747
I've written a classifier and now want to apply it to detect images. My classifier's already got models for HoG features of some objects I'm interested in. I've got the sliding window thing going, which will slide across the image at different scales as well, and I can get the HoG features for each window. My questions is - what's the next step?
Is it really as simple as matching the model's HoG features against the features from the window? I understand that with integral images, there's a threshold value for each class (such as face
or not face
) and if the computed value of the window-generated image is close enough to the class's values and doesn't cross a threshold, then we say that we've got a match.
But how does it work with HoG features?
Upvotes: 0
Views: 3136
Reputation: 2449
Yes, it is as simple as that. Once you have your HOG model and your windows, you anly need to apply the window features to the models. And then select the best result (using a threshold or not, depending on your application).
Here you have a sample code that performs the same steps. The key part is the following:
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
For each window, the code extracts the HOG descriptor and stores them in featureVector
. Then using svmclassify
the code detects the windows where the object is present.
Upvotes: 3