Detector Implementation
To implement the sliding window detector, I took each normalized, grayscale image and scaled it. Then I computed the HOG features of the scaled image using vl_hog. Next I used the template dimensions to create a window equal to the template size. The number of cells per image was the number of hog cells (6). The HOG image was then computed for each window as it traced through the image, and similar to the get_features functions, it created a feature array of the computed (and vectorized) HOG descriptors.
Once the descriptors were computed, their confidence was scored using the w and b values trained with my classifier. The scores for the features were then compared to the threshold and those that were above that level were chosen to compute the bounding boxes.
Here is a code snippet of the sliding window algorithm.
%sliding window
for n = 1 : winx
for m = 1 : winy
%calculate the index of the feature
k = (winy * (n-1) + m);
%crop the image around the feature (for bounding box)
winfeat = hog(m : (m + num_hog_cells - 1), n : (n + num_hog_cells - 1), :);
%reshape to 1x(dimensionality of HOG image) add to descriptor results
window(k, :) = reshape(winfeat, 1, (num_hog_cells^2*31));
end
end
Confidence scoring:
confidence_scores = window * w + b;
best = find(confidence_scores > threshold);