A face detection to check if person is happy and smiling with the aid of OpenCV's Haar Cascade.
Hey gents! Welcome to another post, I've been busy lately been hooked up with some Artificial Intelligence, it has been my meal lately. Read some books and watched some videos to feed up my brain on some neural network. On my previous post I have wrote an article on how an individual AI system can help shape up and protect the future of cybersecurity and our entire industry. Thus, another step-up on humanities' industrial revolution.
In the future, I will be posting some other of my neural net programming exercises, but right now as of this moment I made something that would be more interesting on you readers than some lecture involving Calculus, but will still delve into to that later. Right now I'll open up object classification, specifically face detection.
Image classification is a type of Convolutional Neural Network(CNN), capable of classifying objects and characters with 99% accuracy ,it can also learn features by itself. In this post I made use of Haar by OpenCV for object detection. Haar is a machine learning algorithm where a cascade
function is trained from a lot of positive and negative images.
Right now let's focused on face detection, and how the mentioned algorithm played a role for this. To train the classifier, it would need a lot of images that contain and does not contain a face. It will later find the best threshold which will classify if an object is a face or non-face, from a lot of classification tests which could contain a lot of errors, thus the best feature selected would be the ones with l
ess errors.
On to the Test...
For image's face detection, OpenCV already has the pre-trained classifiers for faces, body, and some others alike. You can check and download some
of the xmls on the link below,
https://github.com/opencv/opencv/tree/master/data/haarcascades
Right now we need the haarcascade_frontalface_default.xml and haarcascade_smile.xml and some pics with haarcascade_eyes.xml to identify whether people on the image is happy with a smile on those faces.
import numpy as np #for some other algorithmic computations
import cv2 #for object detection algorithm
img = cv2.imread('image.jpg') #loaded the desired image to be analyse
**code to check on the pixels, like classifications of lighter and darker areas**
**some more codes for face detections and computations on each edges**
With all that, are the results below:
a. On the image below, is contained with alot of objects but face has been identified and has the smile on the guy's face.
b. Four persons has been deteected to be happy, they can't hide it with those smiles. Though, their could be alot of object noise background, but still the algorithm still does it job well. Also a face must be recognized on the left most part of the image, but not , because a face must have 2 eyes, a mouth , nose and eyebrows, thus the guy on orange is in side view.
c. On this next picture is where the algorithm has been set to challenge. I have added the eye detection on my code on this image. As you can see only one eye has been identified for it fit the code's computation on identifying the shady pixel on what the eye should be, though will still need some fixing on this regard. But the smile detection did not disappoint, for the man covered his mouth, and as for that must not need to be identified as a perfect smile.
d. Last, will be a cute little baby's pic, where all 3 cascades has been detected. A full face, a cute little smile and those two big baby eyes.
That would be it, for this post. Stay tuned for posts like this, as AI is still growing, and so are we =)
Comments