HOG features visualisation with OpenCV, HOGDescriptor in C++

时光总嘲笑我的痴心妄想 提交于 2019-11-29 22:38:11

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:

http://www.juergenbrauer.org/old_wiki/doku.php?id=public:hog_descriptor_computation_and_visualization

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.

KobeJohn

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!