Programing

Viola-Jones의 얼굴 감지 기능으로 180k 기능 주장

lottogame 2020. 10. 13. 07:17
반응형

Viola-Jones의 얼굴 감지 기능으로 180k 기능 주장


저는 Viola-Jones의 얼굴 감지 알고리즘을 적용했습니다 . 이 기술은 이미지 내에 24x24 픽셀의 서브 프레임을 배치 한 다음 가능한 모든 크기의 모든 위치에 직사각형 특징을 배치하는 데 의존합니다.

이러한 기능은 2 개, 3 개 또는 4 개의 직사각형으로 구성 될 수 있습니다. 다음 예가 표시됩니다.

직사각형 기능

그들은 완전한 세트가 180k 이상이라고 주장합니다 (섹션 2) :

감지기의 기본 해상도가 24x24라는 점을 감안할 때 전체 직사각형 기능 집합은 180,000 이상으로 상당히 큽니다. Haar 기반과 달리 직사각형 기능 세트가 과도하게 완성되었습니다.

다음 진술은 논문에 명시 적으로 언급되지 않았으므로 내 입장에서 가정합니다.

  1. 2 개의 직사각형 피처 2 개, 세 개의 직사각형 피처 2 개, 4 개 직사각형 피처 1 개만 있습니다. 이것의 논리는 명시 적으로 색상이나 휘도 또는 그런 종류의 어떤 것도 아닌 강조 표시된 사각형 간의 차이관찰 한다는 것입니다.
  2. 기능 유형 A를 1x1 픽셀 블록으로 정의 할 수 없습니다. 최소 1x2 픽셀 이상이어야합니다. 또한 유형 D는 2x2 픽셀 이상이어야하며이 규칙은 다른 기능에 따라 적용됩니다.
  3. 중간 픽셀을 분할 할 수 없기 때문에 특징 유형 A를 1x3 픽셀 블록으로 정의 할 수 없으며 자체에서 빼는 것은 1x2 픽셀 블록과 동일합니다. 이 기능 유형은 짝수 너비에 대해서만 정의됩니다. 또한 피처 유형 C의 너비는 3으로 나눌 수 있어야하며이 규칙은 다른 피처에 따라 유지됩니다.
  4. 너비 및 / 또는 높이가 0 인 특성은 정의 할 수 없습니다. 따라서 xy 를 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++;
                }
            }
        }
    }
}

결과는 162,336 입니다.

Viola & Jones가 말하는 "180,000 개 이상"을 근사화하는 유일한 방법은 가정 # 4를 삭제하고 코드에 버그를 도입하는 것입니다. 여기에는 네 줄을 각각

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

결과는 180,625 입니다. (이렇게하면 피처가 서브 프레임의 오른쪽 및 / 또는 하단에 닿지 않도록 효과적으로 방지 할 수 있습니다.)

당연히 질문 : 구현에서 실수를 했습니까? 표면이 0 인 피쳐를 고려하는 것이 합리적입니까? 아니면 잘못된 방향으로보고 있습니까?


자세히 살펴보면 귀하의 코드가 저에게 맞는 것처럼 보입니다. 이것은 원저자가 하나의 버그를 가지고 있는지 궁금하게 만듭니다. 누군가 OpenCV가 그것을 구현하는 방법을보아야한다고 생각합니다!

그럼에도 불구하고 이해하기 쉽게 만드는 한 가지 제안은 먼저 모든 크기를 검토 한 다음 주어진 크기에 따라 가능한 위치를 반복 하여 for 루프 의 순서를 뒤집는 것입니다.

#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;
}

이전과 동일한 결과 162336


이를 확인하기 위해 4x4 창의 케이스를 테스트하고 모든 케이스를 수동으로 확인했습니다 (1x2 / 2x1 및 1x3 / 3x1 모양은 90도 회전 만 동일하므로 계산하기 쉬움).

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

모두. Viola와 Jones의 논문에는 여전히 약간의 혼란이 있습니다.

In their CVPR'01 paper it is clearly stated that

"More specifically, we use three kinds of features. The value of a two-rectangle feature is the difference between the sum of the pixels within two rectangular regions. The regions have the same size and shape and are horizontally or vertically adjacent (see Figure 1). A three-rectangle feature computes the sum within two outside rectangles subtracted from the sum in a center rectangle. Finally a four-rectangle feature".

In the IJCV'04 paper, exactly the same thing is said. So altogether, 4 features. But strangely enough, they stated this time that the the exhaustive feature set is 45396! That does not seem to be the final version.Here I guess that some additional constraints were introduced there, such as min_width, min_height, width/height ratio, and even position.

Note that both papers are downloadable on his webpage.


Having not read the whole paper, the wording of your quote sticks out at me

Given that the base resolution of the detector is 24x24, 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.

"The set of rectangle features is overcomplete" "Exhaustive set"

it sounds to me like a set up, where I expect the paper writer to follow up with an explaination for how they cull the search space down to a more effective set, by, for example, getting rid of trivial cases such as rectangles with zero surface area.

edit: or using some kind of machine learning algorithm, as the abstract hints at. Exhaustive set implies all possibilities, not just "reasonable" ones.


There is no guarantee that any author of any paper is correct in all their assumptions and findings. If you think that assumption #4 is valid, then keep that assumption, and try out your theory. You may be more successful than the original authors.


꽤 좋은 관찰이지만, 24x24 프레임 또는 "오버플로"를 암시 적으로 0으로 채우고 회전 이동에서와 같이 경계를 벗어날 때 첫 번째 픽셀을 사용하기 시작하거나 Breton이 말한대로 일부 기능을 "사소한 기능"으로 간주 할 수 있습니다. AdaBoost로 폐기하십시오.

또한 Python 및 Matlab 버전의 코드를 작성하여 코드를 직접 테스트 할 수 있으므로 (더 쉽게 디버깅하고 따라갈 수 있음) 누군가 유용하다고 생각되면 여기에 게시합니다.

파이썬 :

frameSize = 24;
features = 5;
# All five feature types:
feature = [[2,1], [1,2], [3,1], [1,3], [2,2]]

count = 0;
# Each feature:
for i in range(features):
    sizeX = feature[i][0]
    sizeY = feature[i][1]
    # Each position:
    for x in range(frameSize-sizeX+1):
        for y in range(frameSize-sizeY+1):
            # Each size fitting within the frameSize:
            for width in range(sizeX,frameSize-x+1,sizeX):
                for height in range(sizeY,frameSize-y+1,sizeY):
                    count=count+1
print (count)

Matlab :

frameSize = 24;
features = 5;
% All five feature types:
feature = [[2,1]; [1,2]; [3,1]; [1,3]; [2,2]];

count = 0;
% Each feature:
for ii = 1:features
    sizeX = feature(ii,1);
    sizeY = feature(ii,2);
    % Each position:
    for x = 0:frameSize-sizeX
        for y = 0:frameSize-sizeY
            % Each size fitting within the frameSize:
            for width = sizeX:sizeX:frameSize-x
                for height = sizeY:sizeY:frameSize-y
                    count=count+1;
                end
            end
        end
    end
end

display(count)

참고 URL : https://stackoverflow.com/questions/1707620/viola-jones-face-detection-claims-180k-features

반응형