Python | Face recognition using GUI
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:
Step 1: pip install opencv-python
Step 2: 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 cascade 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 :