OpenCV provides a nice face detection framework. We just need to load the cascade file and use it to detect the faces in an image. When we capture a video stream from the webcam, we can overlay funny masks on our faces. It will look something like this:
Let's look at the main parts of the code to see how to overlay this mask on the face in the input video stream. The full code is available in the downloadable code bundle provided along with this book:
#include "opencv2/core/utility.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
using namespace cv;
using namespace std;
...
int main(int argc, char* argv[]) { string faceCascadeName = argv[1]; // Variable declaration and initialization ...
// Iterate until the user presses...