
OpenCV By Example
By :

Now that we understand how to detect faces, we can generalize this concept to detect different parts of the face. We will use an eye detector to overlay sunglasses in a live video. It's important to understand that the Viola-Jones framework can be applied to any object. The accuracy and robustness will depend on the uniqueness of the object. For example, a human face has very unique characteristics, so it's easy to train our system to be robust. On the other hand, an object such as a towel is too generic, and there are no distinguishing characteristics as such. So, it's more difficult to build a robust towel detector.
Once you build the eye detector and overlay glasses on top of it, it will look something like this:
Let's take a look at the main parts of the code:
int main(int argc, char* argv[]) { string faceCascadeName = argv[1]; string eyeCascadeName = argv[2]; // Variable declarations and initializations // Face detection code vector...