Number of haar like features in 24x24 window

和自甴很熟 提交于 2020-03-20 04:49:36

问题


Referring to the following link

Viola & Jones Face Detection

The above link contains the calculation regarding the number of haar features corresponding to different templates(below is excerpt from the link).

I am not getting how those(43200,27600,43200,27600,20736) exact calculations are made.Can somebody explain that to me in an easy way?


回答1:


To understand, have a look at the algorithm #1. For the first pattern (a), the following two lines (5 and 6 in the article) gives the explanations

for all(i,j) such 1<=i<=24 and 1<=j<=24:
  for all(h,w) such that i+h-1<=24 and j+2w-1<=24:

This means you will take all the combinations of top-left corners (i is top, and j is left), then all the combinations of width (w) and heights (h) that will fit inside the 24x24.

The algorithm will also use all combinations of widths and heights (1x4, 1x6, 1x8, ..., 1x24, 2x2, 2x4, 2x6, 2x8, ..., 2x24, 3x2, 3x4, 3x6, ..., up to 24x24). As long as widths are a multiple of 2 (specified by 2w in line #6).

The smallest pattern (2 pixels wide and 1 pixel high) will fit in 24 * 23 = 552 positions (23 horizontal positions, and 24 vertical positions).

At some point, for example, you will have a 7x10 pattern (7 pixels height, and 10 pixels wide). It will fit in 18 x 15 = 270 positions (18 vertical positions and 15 horizontal positions).

The biggest rectangle (24x24 pixels), will consist of 12 white columns followed by 12 black columns. It will fit in only one position (the whole image).

If you sum all the positions for all possible dimensions, you obtain the numbers.

To get the first number (for pattern a), the following program (I did not optimize it! but it should be easily understandable) prints 43200:

# Pattern A
total = 0
for i in range(1,25):     # 1 <= i <= 24
  for j in range(1,25):     # 1 <= j <= 24
    for w in range(1,13):     # 2*w=2,4,6,...24
      for h in range(1,25):     # h=1,2,...,24
        if (i+h-1<=24) and (j+2*w-1<=24):
          total += 1
print total

Explanations are similar for other patterns.



来源:https://stackoverflow.com/questions/40198217/number-of-haar-like-features-in-24x24-window

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