In this article, a fairly simple way is mentioned to implement facial recognition system using Python and OpenCV module along with the explanation of the code step by step in the comments.
Before starting we need to install some libraries in order to implement the code. Below you will see the usage of the library along with the code to install it:
OpenCV (Open Source Computer Vision Library) is an open-source computer vision and machine learning software library. which is built to provide a common infrastructure for machine learning algorithms and computer vision. It has thousands of optimized algorithms which can be used different purposes like detecting and recognizing faces, identifying objects and many more. We need it to take pictures using our webcam and some manipulation needed to be done in the image.
To install the library you need to install pip in your system after that you can follow the steps in command prompt:
pip install opencv-python
pip install opencv-contrib-python
NumPy is the fundamental package for scientific computing in Python which provides a multidimensional array object other mathematical operations can be performed using this but simply speaking we just need it to convert our images into some form of an array so that we can store the model that has been trained.
To install the library you can type a simple line of code in your command shell:
pip install numpy
- Haar Cascade:
Haar Cascade is basically a classifier which is used to detect the objects for which it has been trained for, from the source. The result is an XML file which stores the trained result. If said simply the Haar Cascade is trained by superimposing the positive image over a set of negative images. The training requires a high spec system and a good internet connection and thousands of training images that is why it is carried out in the server. For increasing the efficiency of the results they use high-quality images and increase the number of stages for which the classifier is trained. We need haar cascade frontal face recognizer to detect the face from our webcam.
To download the haar casade files of different objects you can go the below link:
- Python GUI (tkinter):
Tkinter is a simple GUI module used for implementing fairly simple GUI and helps us to interact with code in a simple way. Though for understanding the code its not important for you to know how it works.
If you wanna learn more about Tkinter click the link below
Python GUI – tkinter
Code: Python implementing to recognize face using GUI
Sample Image of the GUI:
Folder Structure For reference :
- Python | Multiple Face Recognition using dlib
- Deep Face Recognition
- ML | Face Recognition Using PCA Implementation
- ML | Face Recognition Using Eigenfaces (PCA Algorithm)
- ML | Implement Face recognition using k-NN with scikit-learn
- Python | Named Entity Recognition (NER) using spaCy
- Google Chrome Dino Bot using Image Recognition | Python
- Python | Reading contents of PDF using OCR (Optical Character Recognition)
- Python | Speech recognition on large audio files
- ML | Unsupervised Face Clustering Pipeline
- Applications of Pattern Recognition
- Pattern Recognition | Introduction
- FaceNet - Using Facial Recognition System
- Pattern Recognition | Basics and Design Principles
- Human Activity Recognition - Using Deep Learning Model
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.