I use the HOGDescriptor of the OpenCV C++ Lib to compute the feature vectors of an images. I would like to visualize the features in the source image. Can anyone help me?
I had exactly the same problem today. Computing a HOGDescriptor
vector for a 64x128 image using OpenCV's HOGDescriptor::compute()
function is easy, but there is no built-in functionality to visualize it.
Finally I managed to understand how the gradient orientation magnitudes are stored in the 3870 long HOG descriptor vector.
You can find my C++ code for visualizing the HOGDescriptor
here:
Hope it helps!
Jürgen
HOGgles¹ is a method developed for HOG visualization, published on ICCV 2013. Here is an example:
This visualization tool may be more useful than plotting the gradient vectors of HOG because one can see better why HOG failed for a given sample.
More information can be found here: http://web.mit.edu/vondrick/ihog/
¹C. Vondrick, A. Khosla, T. Malisiewicz, A. Torralba. "HOGgles: Visualizing Object Detection Features" International Conference on Computer Vision (ICCV), Sydney, Australia, December 2013.
This opencv group discussion leads to a library written at Brown University.
In HOGpicture.m
you should be able to get an idea how to visualize the descriptors. Here is the relevant (matlab) code. Is it enough for you to make something for yourself?
(below code is released under an MIT license)
function im = HOGpicture(w, bs)
% HOGpicture(w, bs)
% Make picture of positive HOG weights.
% construct a "glyph" for each orientation
bim1 = zeros(bs, bs);
bim1(:,round(bs/2):round(bs/2)+1) = 1;
bim = zeros([size(bim1) 9]);
bim(:,:,1) = bim1;
for i = 2:9,
bim(:,:,i) = imrotate(bim1, -(i-1)*20, 'crop');
end
% make pictures of positive weights bs adding up weighted glyphs
s = size(w);
w(w < 0) = 0;
im = zeros(bs*s(1), bs*s(2));
for i = 1:s(1),
iis = (i-1)*bs+1:i*bs;
for j = 1:s(2),
jjs = (j-1)*bs+1:j*bs;
for k = 1:9,
im(iis,jjs) = im(iis,jjs) + bim(:,:,k) * w(i,j,k);
end
end
end
I reimplement HOGImage for any blockSize
and cellSize
, which is based on Jürgen Brauer's. See https://github.com/zhouzq-thu/HOGImage.
来源:https://stackoverflow.com/questions/10862542/hog-features-visualisation-with-opencv-hogdescriptor-in-c