﻿ 算法 – Viola-Jones的面部检测声称有180k的功能 - 代码日志

#### 算法 – Viola-Jones的面部检测声称有180k的功能

Given that the base resolution of the detector is 24×24, the exhaustive set of rectangle features is quite large, over 180,000 . Note that unlike the Haar basis, the set of rectangle
features is overcomplete.

>只有2个双矩形特征，2个三矩形特征和1个四矩形特征。这背后的逻辑是，我们观察突出显示的矩形之间的差异，而不是明确的颜色或亮度或任何类别。
>我们不能将要素类型A定义为1×1像素块;它必须至少是至少1×2像素。此外，类型D必须至少为2×2像素，并且此规则相应地适用于其他特征。
>我们不能将特征类型A定义为1×3像素块，因为中间像素不能被分割，并且从其自身减去与1×2像素块相同;此功能类型仅针对均匀宽度进行定义。此外，特征类型C的宽度必须可除以3，并且该规则相应地适用于其他特征。
>我们不能定义宽度和/或高度为0的特征。因此，我们将x和y迭代为24减去特征的大小。

``````const int frameSize = 24;
const int features = 5;
// All five feature types:
const int feature[features][2] = {{2,1}, {1,2}, {3,1}, {1,3}, {2,2}};

int count = 0;
// Each feature:
for (int i = 0; i < features; i++) {
int sizeX = feature[i][0];
int sizeY = feature[i][1];
// Each position:
for (int x = 0; x <= frameSize-sizeX; x++) {
for (int y = 0; y <= frameSize-sizeY; y++) {
// Each size fitting within the frameSize:
for (int width = sizeX; width <= frameSize-x; width+=sizeX) {
for (int height = sizeY; height <= frameSize-y; height+=sizeY) {
count++;
}
}
}
}
}
``````

``````for (int width = 0; width < frameSize-x; width+=sizeX)
for (int height = 0; height < frameSize-y; height+=sizeY)
``````

``````#include <stdio.h>
int main()
{
int i, x, y, sizeX, sizeY, width, height, count, c;

/* All five shape types */
const int features = 5;
const int feature[][2] = {{2,1}, {1,2}, {3,1}, {1,3}, {2,2}};
const int frameSize = 24;

count = 0;
/* Each shape */
for (i = 0; i < features; i++) {
sizeX = feature[i][0];
sizeY = feature[i][1];
printf("%dx%d shapes:\n", sizeX, sizeY);

/* each size (multiples of basic shapes) */
for (width = sizeX; width <= frameSize; width+=sizeX) {
for (height = sizeY; height <= frameSize; height+=sizeY) {
printf("\tsize: %dx%d => ", width, height);
c=count;

/* each possible position given size */
for (x = 0; x <= frameSize-width; x++) {
for (y = 0; y <= frameSize-height; y++) {
count++;
}
}
printf("count: %d\n", count-c);
}
}
}
printf("%d\n", count);

return 0;
}
``````

``````2x1 shapes:
size: 2x1 => count: 12
size: 2x2 => count: 9
size: 2x3 => count: 6
size: 2x4 => count: 3
size: 4x1 => count: 4
size: 4x2 => count: 3
size: 4x3 => count: 2
size: 4x4 => count: 1
1x2 shapes:
size: 1x2 => count: 12             +-----------------------+
size: 1x4 => count: 4              |     |     |     |     |
size: 2x2 => count: 9              |     |     |     |     |
size: 2x4 => count: 3              +-----+-----+-----+-----+
size: 3x2 => count: 6              |     |     |     |     |
size: 3x4 => count: 2              |     |     |     |     |
size: 4x2 => count: 3              +-----+-----+-----+-----+
size: 4x4 => count: 1              |     |     |     |     |
3x1 shapes:                                |     |     |     |     |
size: 3x1 => count: 8              +-----+-----+-----+-----+
size: 3x2 => count: 6              |     |     |     |     |
size: 3x3 => count: 4              |     |     |     |     |
size: 3x4 => count: 2              +-----------------------+
1x3 shapes:
size: 1x3 => count: 8                  Total Count = 136
size: 2x3 => count: 6
size: 3x3 => count: 4
size: 4x3 => count: 2
2x2 shapes:
size: 2x2 => count: 9
size: 2x4 => count: 3
size: 4x2 => count: 3
size: 4x4 => count: 1
``````