Strictly Finding Smiles

Strictly as in finding smiles and nothing else. As I said in my last blog, I could find mouths, and according to the haarcascade detection file I was using (haarcascade_smile.xml) every mouth is a smile. I took a look at the OpenCV documentation (I threatened to do that a few blogs ago) and found two parameters I could add to detectMultiScale; my detection for smiles now looks like
smile = smile_cascade.detectMultiScale(roi_gray, 6.5, 5, flags=cv2.CASCADE_SCALE_IMAGE);
I added the CASCADE_SCALE_IMAGE in my last blog; 6.5 and 5 were added for this blog. 6.5 is for ScaleFactor ( Parameter specifying how much the image size is reduced at each image scale), and the 5 is for minNeighbors ( Parameter specifying how many neighbors each candidate rectangle should have to retain it). For a video of myself (see below) those worked as the best values for these two new parameters (arguments). However, I downloaded some videos from the Internet, and I had to change the argument values to maintain good results. You can see I'm missing a tooth in this video; that probably affects smile detection, versus the models in the downloaded videos (they had full sets of teeth).:

Still not perfect, but my script did a pretty decent job finding smiles only when I smiled. To make it perfect I probably need to parse out the components of haarcascade_smile.xml (internalNodes and leafValues) and compare how well they fit corresponding values in the video. This is what detectsmiles.cpp does (NOTE: This isn't what detectsmiles.cpp is doing. That stuff about parsing out the components of the xml files is what looked like the program was doing from a cursory glance. detectsmiles.cpp is counting the number of hits on the face, and other spots on the image as well. The more hits, the better a match the image is as a smile. This means that the smile detection is done over the whole image, not just the mouth region, like I was trying to do with my Python program.):
https://github.com/opencv/opencv/blob/master/samples/cpp/smiledetect.cpp>
I downloaded the code for detectsmiles.cpp and then found out the copy of OpenCV I have doesn't support VC++ 2010 (the version of VC++ I already had on my system). I downloaded Visual Studio 2015, set it up to use OpenCV (the VC14 libraries), compiled detectsmiles.cpp and ran it; it did a great job. detectsmiles.cpp put a vertical bar on the left side of the video, where the height of the bar (rectangle) denotes how well the smile in the video matches the "hit" we just got in the haarcascade_smile.xml file. I plan on incorporating the the technique I learned in detectsmiles.cpp, but first I'm going to look into a way to accomplish the same in Python, but if there is nothing comparable in Python, I'll switch to C++ for this program.

Return To My Blog Page       Streaming Video Script       Return To My Programming Page