Professional Documents
Culture Documents
html
Cascade Classifier
Goal
In this tutorial you will learn how to:
Use the cv::CascadeClassifier class to detect objects in a video stream. Particularly, we will use the functions:
cv::CascadeClassifier::load to load a .xml classifier file. It can be either a Haar or a LBP classifer
cv::CascadeClassifier::detectMultiScale to perform the detection.
Theory
Code
This tutorial code's is shown lines below. You can also download it from here
#include "opencv2/objdetect.hpp"
#include "opencv2/videoio.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>
#include <stdio.h>
cout << "\nThis program demonstrates using the cv::CascadeClassifier class to detect objects (Face + eyes) in a video
stream.\n"
"You can use Haar or LBP features.\n\n";
parser.printMessage();
1 of 4 8/21/2017, 8:15 AM
OpenCV: Cascade Classifier http://docs.opencv.org/trunk/db/d28/tutorial_cascade_classifier.html
face_cascade_name = parser.get<string>("face_cascade");
eyes_cascade_name = parser.get<string>("eyes_cascade");
VideoCapture capture;
Mat frame;
2 of 4 8/21/2017, 8:15 AM
OpenCV: Cascade Classifier http://docs.opencv.org/trunk/db/d28/tutorial_cascade_classifier.html
}
//-- Show what you got
imshow( window_name, frame );
}
Explanation
Result
1. Here is the result of running the code above and using as input the video stream of a build-in webcam:
Be sure the program will find the path of files haarcascade_frontalface_alt.xml and haarcascade_eye_tree_eyeglasses.xml. They are located in
opencv/data/haarcascades
3 of 4 8/21/2017, 8:15 AM
OpenCV: Cascade Classifier http://docs.opencv.org/trunk/db/d28/tutorial_cascade_classifier.html
2. This is the result of using the file lbpcascade_frontalface.xml (LBP trained) for the face detection. For the eyes we keep using the file used in the
tutorial.
4 of 4 8/21/2017, 8:15 AM