3

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). enter image description here

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?

Community
  • 1
  • 1
Naseer
  • 3,147
  • 5
  • 31
  • 61
  • Have a look here: https://stackoverflow.com/questions/1707620/viola-jones-face-detection-claims-180k-features – Andreas K. Jun 23 '20 at 09:55

1 Answers1

4

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.

Sci Prog
  • 2,503
  • 1
  • 7
  • 17