FACIAL RECOGNITION USING PYTHON OPENCV
19.09.2022 21:30
[1. Інформаційні системи і технології]
Автор: Бровіна Оксана Іванівна, студент, Криворізький національний університет, м. Кривий Ріг; Іосіпов Роман Костянтинович, студент, Криворізький національний університет, м. Кривий Ріг
A facial recognition system is a certain technology capable of identifying or verifying an individual in a video frame, digital image, or any similar resource. There are many methods used in these systems, but in general they are based on comparing the facial features given by the image with the faces stored in the database. This type of application is a certain artificial intelligence-based biometric application that can uniquely identify a person by analyzing patterns based on facial textures and a person's shape.
The development of facial recognition software and the improvement of already existing algorithms are done by programmers of various languages (mainly Python, C++, Java, C#) and data-scientists.
In the field of artificial intelligence, computer vision tasks are among the most interesting and complex. Computer vision works as a bridge between computer software and the visual picture around us. It gives software the ability to understand and learn everything visible in the environment.
The most common method, which is still used in many algorithms today, is the Viola-Jones method using Hoare signs. This method is based on finding the main contour and further research of its properties. Properties are defined as a certain set of geometric shapes with a black and white pattern, which help to find the boundaries of a certain shape, for example, the shape of the face, the line of the nose, the mouth, or the eyes.
The result is compared with the limit value. If the result is less than the threshold value, then there is no person in the part of the frame, and the algorithm finishes its work. And if it is more, then it goes to the next part of the frame. So, the facial recognition algorithm can be presented in the form of a diagram. Currently, there are various packages for machine learning, deep learning, and computer vision tasks. And certainly, the module responsible for computer vision is developed better than others. OpenCV is an open source library. It supports various programming languages such as R and Python.
Figure 1 - Algorithm of face recognition
It can work on many platforms, including Windows, Linux and MacOS. Some advantages of OpenCV:
• Completely free and open source;
• Written in C++, and, compared to some libraries, works faster;
• Does not require a lot of memory;
• Supports all the most popular operating systems;
The algorithms of the OpenCV library work as follows: each face has its own characteristics, for example, each face has light and dark areas (light - forehead, cheeks, chin; dark - eyes, lips, etc.); also, the faces of all people are built according to the general principle - the eyes are on the same line, the nose is under the eyes, and the lips are under the nose, etc. Based on these characteristics, you can choose a set of masks and code a program that will take into account all these features.
The OpenCV library is very easy to install in the console (we will use the Python language), separately it has the face_recognition application, which was developed by Adam Gaitgey and is a kind of superstructure on top of the main library.
To write your own facial recognition program, you first pass the images and cascade names as command-line arguments. We will use the standard face detection cascade provided by OpenCV. After that, we read the image and convert it to grayscale. Many operations in OpenCV are performed in grayscale.
The first option is to make an image in grayscale.
The second option is scaleFactor. Because some faces may be closer to the camera, they will appear larger than faces behind them. The scale factor compensates for this.
The detection algorithm uses a moving window to detect objects. The program determines how many objects will be detected near the current one before it announces a face found. Meanwhile, another function determines the size of each window. The function returns a list of rectangles in which it thinks a face is found, and also returns 4 values: the x and y position of the rectangle, and the width and height of the rectangle (w, h).
We use these values to draw a rectangle using the rectangle() built-in function. At the end, we show the image and wait for the user to press a key, and then the application is ready.
References:
1. Face recognition in OpenCV [Електронний ресурс] / Режим доступу: https://pyimagesearch.com/2018/09/24/opencv-face-recognition/
2. Face recognition with Python, in under 25 lines of code [Електронний ресурс] / Режим доступу:
https://realpython.com/face-recognition-with-python/
3. Face recognition 1.3.0 [Електронний ресурс] / Режим доступу:
https://pypi.org/project/face-recognition/
4. Face recognition system using Python [Електронний ресурс] / Режим доступу:
https://www.analyticsvidhya.com/blog/2022/04/face-recognition-system-using-python/