How to Build a Face Recognition using OpenCV Library, DLib

In order for the system to function, it’s necessary to implement three steps. First, it must detect a face. Then, it must recognize that face nearly instantaneously. Finally, it must take whatever further action is required, such as allowing access for an approved user.

My teammate in the video explains the idea in general, and below you can read a more detailed description.

Face detection and recognition process

The facial recognition process begins with an application for the camera, installed on any compatible device in communication with said camera. The application is programmed in Golang, and works with both Raspbian and Ubuntu as a local console app. When the application is first launched, it requires being configured using a JSON config file with Local Camera ID and Camera Reader type.

This application is then able to use computer vision and a deep neural network in order to find a prospective face within its stream. There are two primary effective ways to do so: The first is the TensorFlow object detection model and the second is Caffe face tracking. Both these methods have functioned well, and are a part of the OpenCV library.

How to build a face recognition using OpenCV library, DLib

Once a face has been captured, the cropped image will be relayed with an HTTP form data request to the back end. This facial image is then saved by the API, both on the local file system and in the detection log, appended with a personID.

On the back end, an algorithm identifies records where ‘classified=false’ and uses the Dlib function to generate the 128-dimension vector that details this face’s attributes. The algorithm then cross-references this vector with all of the facial entries in the database using Euclidean distance in order to discover whether this new face is a match with any faces on record.

How to build a face recognition using OpenCV library, DLib

Pictured below is a representation of the Dlib function’s code, with the index points corresponding to parts of the face.

How to build a face recognition using OpenCV library, DLib

After calculating Euclidean distance, the algorithm will either generate a new personID for an unknown type person (if the distance is greater than 0.6) or marks the face as classified and matches the personID (if the distances is less than 0.6).

When a face turns up as unidentified, this image can be relayed to a manager or supervisor along with a notification via a chatbot in a messenger program, or some other means. The manager or supervisor would be presented with an array of options on how to handle the situation from that point forward.

How to build a face recognition using OpenCV library, DLib

Implementing a simple chatbot alert system takes around two to five days, and can be created with utilities like Errbot (Python based) or Microsoft’s Bot Framework.

Facial records are available for after-the-fact management through Admin Panel. This space will contain a linking of all recorded images with their ID numbers. It’s possible to create a database of all relevant employees’ facial images, which can be put into the database before the system goes live.

One issue that potentially arises is that of scaling. In our case there are about 200 entries in the database, so the system can seamlessly process and recognize faces instantly. Things become more complicated when databases swell into the tens of thousands of entries, or if multiple cameras are required. Processing speed will slow down if no countermeasures are taken.

Fortunately, parallelization offers a solution. It’s possible to create a load balancer and multiple Web workers which are able to work at the same time. This allows the database to be divided into subsections, which produces significantly faster search results.

The following is a summary of both the technologies implemented and the overall structure of this facial recognition solution.

How to build a face recognition using OpenCV library, DLib

API requests within the solution use RESTful API, and back end employee data collection uses MongoDB Collections and Golang. It would be possible to use a regular workstation setup to test the solution.

It’s important to note that supporting security measures can and probably should enhance facial recognition. An image of a face is far easier to obtain than a retinal scan or fingerprints. If the security needs are vital enough, taking extra anti-spoofing measures ensure that no one is able to defeat a facial recognition system with a photograph or image of a face.

Significant quantities of data can be worked with by this solution, and others like it. Assuming an enterprise were able to coordinate with well-articulated business needs, data science models would be able to deliver business insights.

Face recognition is only the beginning of implementing this method. A human face is just one of the objects to be detected. Other objects can be identified in the same manner. For example, it can be vehicles, furniture items, flowers, animals, if a DS model is created and trained on dataset with the objects.

Moreover, it’s possible to develop a multimodal biometric system, combining two or more biometric credentials, for example, face and voice recognition. I will write about this in my next article.

#opencv #machine-learning #deep-learning #artificial-intelligence #data-science

How to Build a Face Recognition using OpenCV Library, DLib
35.70 GEEK