ChHaupt
ChHaupt

Reputation: 363

HOG features visualisation with OpenCV, HOGDescriptor in C++

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?

Upvotes: 17

Views: 28460

Answers (3)

Zhiqiang Zhou
Zhiqiang Zhou

Reputation: 39

I reimplement HOGImage for any blockSize and cellSize, which is based on Jürgen Brauer's. See https://github.com/zhouzq-thu/HOGImage.

Upvotes: 2

KobeJohn
KobeJohn

Reputation: 7545

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

Upvotes: 2

Yamaneko
Yamaneko

Reputation: 3563

HOGgles¹ is a method developed for HOG visualization, published on ICCV 2013. Here is an example:

What does HOG sees?

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.

Upvotes: 13

Related Questions