That's pretty cool! But recognizing faces in images is not something terribly new and exciting. Wouldn't it be great if we could tell OpenCV to recognize something of our choice, something that is not a face? Let's say... a banana? That is totally possible! Here's the good news: we can generate our own cascade classifier for Haar features. But now for the best of news: keep on reading! The following instructions are heavily based on Naotoshi Seo's immensely helpful notes on OpenCV haartraining and make use of his scripts and resources he released under the MIT licencse. Let's get started The first thing you need to do is clone the repository on GitHub I made for this post. Git clone You'll also need OpenCV on your system. If you're on OS X and use homebrew it's as easy as this: Samples How many images do we need? Tutorial: OpenCV haartraining (Rapid Object Detection With A Cascade of Boosted Classifiers Based on Haar-like Features) - Naotoshi Seo.
Tutorial: OpenCV haartraining (Rapid Object Detection With A Cascade of Boosted Classifiers Based on Haar-like Features) Objective The OpenCV library provides us a greatly interesting demonstration for a face detection.
Furthermore, it provides us programs (or functions) that they used to train classifiers for their face detection system, called HaarTraining, so that we can create our own object classifiers using these functions. It is interesting. However, I could not follow how OpenCV developers performed the haartraining for their face detection system exactly because they did not provide us several information such as what images and parameters they used for training. My working environment is Visual Studio + cygwin on Windows XP, or on Linux. FYI: I recommend you to work haartrainig with something different concurrently because you have to wait so many days during training (it would possibly take one week).
A picture from the OpenCV website History Data Prepartion. Python - Using OpenCV and Haar cascade classifiers to detect faces on video streams. Cascade Classification. Haar Feature-based Cascade Classifier for Object Detection The object detector described below has been initially proposed by Paul Viola Viola01 and improved by Rainer Lienhart Lienhart02 . First, a classifier (namely a cascade of boosted classifiers working with haar-like features ) is trained with a few hundred sample views of a particular object (i.e., a face or a car), called positive examples, that are scaled to the same size (say, 20x20), and negative examples - arbitrary images of the same size. After a classifier is trained, it can be applied to a region of interest (of the same size as used during the training) in an input image.
The classifier outputs a “1” if the region is likely to show the object (i.e., face/car), and “0” otherwise. To search for the object in the whole image one can move the search window across the image and check every location using the classifier. A simple demonstration of face detection, which draws a rectangle around each detected face: Soft Cascade Classifier — OpenCV 2.4.9. Soft Cascade Classifier for Object Detection Cascade detectors have been shown to operate extremely rapidly, with high accuracy, and have important applications in different spheres.
The initial goal for this cascade implementation was the fast and accurate pedestrian detector but it also useful in general. Soft cascade is trained with AdaBoost. But instead of training sequence of stages, the soft cascade is trained as a one long stage of T weak classifiers. Soft cascade is formulated as follows: where are the set of thresholded weak classifiers selected during AdaBoost training scaled by the associated weights. Be the partial sum of sample responses before -the weak classifier will be applied. Of for sample named sample trace. Is compared with the rejection threshold . Named rejection trace. The sample has been rejected if it fall rejection threshold. That confidence depend on all previous weak classifier. SCascade class SCascade Implementation of soft (stageless) cascaded detector. Cascade Classifier. Goal In this tutorial you will learn how to: Use the CascadeClassifier class to detect objects in a video stream.
Particularly, we will use the functions:load to load a .xml classifier file. It can be either a Haar or a LBP classiferdetectMultiScale to perform the detection. Code.