Facial Recognition Machine Learning with Python & OpenCV
In this tutorial there will be 3 phases : Collecting dataset , training model, face recognition
1. Collecting/Creating dataset
In this phase we will talk about what is the function of collecting datasets and how can it be done. Collecting dataset in this application is mainly purpose for training the model to understand what makes that pictures is your face or maybe your friends face. We need a program to detect the faces and then crop it and save it to the datasets folder (/datasets). This datasets directory will then later be used to train our model later on in the next phase.
The first task is to identify reliable patterns in the face as show above. This can be determined using the technique described below. In this phase and this program we gonna be using haar-cascade classifier to identify which part of the image is a `face` or is it not.
A Haar-like feature considers neighbouring rectangular regions at a specific location in a detection window, sums up the pixel intensities in each region and calculates the difference between these sums. This difference is then used to categorize subsections of an image.
In this example the areas around the eyes are darker than the areas on the cheeks. One example of a Haar-like feature for face detection is therefore a set of two neighbouring rectangular areas above the eye and cheek regions.
The cascade-classifier consist of few stages, where each stage consists of a list of weak learners. The system detects objects in question by moving a window over the image. Each stage of the classifier labels the specific region defined by the current location of the window as either positive or negative – positive meaning that an object was found or negative means that the specified object was not found in the image.
Thus after getting the image of face, we can then instruct python to capture and crop(to get the image inside the rectangle only) the image. An image is taken per 100 milliseconds and since we gonna need 100 datasets of a user/model so there should be 100 images captures for a user.
For this program, we took about 100 face images as training dataset per person, because it will be good to have more training datasets to train our model. This will be explain further in our training phase. The trained model can learnt the person's face more if we give it more data.
Further information article can be read from:
- Object Detection using Haar-cascades Classifier
- Face Detection using Haar Cascades
- Object Detection using Haar‐like Features
2. The Training
Supposedly we already have/collected the sample 100 datasets of a model. In this phase the training data must contain the correct answer, which is known as a target or target attribute. The learning algorithm finds patterns in the training data that map the input data attributes to the target (the answer that you want to predict), and it outputs an ML model that captures these patterns. Thus the trained model will later be saved and use for face recognition.
In this phase we will be using Local Binary Pattern Histogram(LBPH) for understanding and pattern analysis of the face structure. We will extract the information and generalize it, thus it can learn which face belongs to whom.
The first step in constructing the LBP texture descriptor is to convert the image to grayscale. For each pixel in the grayscale image, we select a neighbourhood of size r surrounding the center pixel. A LBP value is then calculated for this center pixel and stored in the output 2D array with the same width and height as the input image.
Three neighbourhood examples with varying p and r used to construct Local Binary Patterns.
Then pass the features onto our Linear SVM for classification.
Now since we have train using the training model, we save our trained model.
Further information article can be read from:
- Local Binary Patterns with Python & OpenCV
3. Face Recognition
Lastly we have reach our final phase which is the face recognition.
Thus since we have gather all our datasets and train our model to understand the image from the datasets given, we can now test our face classification system.
Our model should now be able to classified the image they view and recognize them based on the pattern and model trained.
FULL SOURCECODE:
- Face Recognition with python and open CV - https://github.com/nazmi69/Face-Recognition/ ~ program by Nazmi Asri
Guide to setup and test:
- Face Recognition with python & open CV - https://github.com/nazmi69/Face-Recognition/blob/master/README.md
Video Sample:
- Face recognition using Python - https://www.facebook.com/nazmi69/videos/1706995102662744/
Note: This is not a software release this is merely a basic guide to develop a ML Face Recognition with python and OpenCV
Thank you for posting this.Hormone optimization Wellington You most absolutely have built this blog website into something special.
ReplyDeleteLucky Lucky Casino 1077 Riverside Rd New York, NY - MapyRO
ReplyDeleteGet directions, reviews 청주 출장마사지 and information for Lucky 포항 출장샵 Lucky 경상남도 출장샵 Casino in New York, NY. A casino floor is the biggest and 천안 출장안마 largest in the 군산 출장안마 U.S. with over 1,500 slot