Skip to content

Cascading classifiers

필터를 사용하여 객체를 인식.

Cascading is a particular case of ensemble learning based on the concatenation of several classifiers, using all information collected from the output from a given classifier as additional information for the next classifier in the cascade. Unlike voting or stacking ensembles, which are multiexpert systems, cascading is a multistage one.

Cascading classifiers are trained with several hundred "positive" sample views of a particular object and arbitrary "negative" images of the same size. After the classifier is trained it can be applied to a region of an image and detect the object in question. To search for the object in the entire frame, the search window can be moved across the image and check every location with the classifier. This process is most commonly used in image processing for object detection and tracking, primarily facial detection and recognition.

The first cascading classifier was the face detector of Viola and Jones (2001). The requirement for this classifier was to be fast in order to be implemented on low-power CPUs, such as cameras and phones.

Haar Cascades

XML 파일은 haarcascade_frontalface_default.xml 에서 다운로드. 이미지는 아무 사람 얼굴 다운로드.

import cv2
from datetime import datetime

image = cv2.imread("test.png")
cascade_face_detector = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")

while True:
    begin = datetime.now()
    face_detections = cascade_face_detector.detectMultiScale(image)
    for (x, y, w, h) in face_detections:
        cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)
    duration = (datetime.now() - begin).total_seconds()
    print(duration)

    cv2.imshow('demo', image)
    if cv2.waitKey(1) == ord('q'):
        exit(1)

OpenCV 훈련 방법

OpenCV:CascadeClassifier 항목 참조.

See also

Favorite site

Offical Tutorials

OpenCV Guide

Training