Face Recognition By Comparing Unknown Faces with Known Faces

Face Recognition:

Face recognition is a method of identifying or verifying the identity of an individual using their face. Face recognition systems can be used to identify people in photos, video, or in real-time.

It is a technology capable of matching a human face from a digital image or a video frame against a database of faces, typically employed to authenticate users through ID verification services, works by pinpointing and measuring facial features from a given image.

While initially a form of computer application, facial recognition systems have seen wider uses in recent times on smartphones and in other forms of technology, such as robotics

Process

We gonna use Python language to implement face recognition. At First, We need to detect faces in a given image by the coordinates of each face, which is detected by the trained CNN model and then the face got cropped from the images, The next step is recognizing faces with the cropped images.

For Visualizing , Drawing shapes, read and manipulate image files, we use open cv, which is a framework, that is used to do processes with images and other things too. You can get more details in the documentation https://docs.opencv.org/master/de/d7a/tutorial_table_of_content_core.html

Python Modules Used

face-recognition,mtcnn,tensorflow,cmake,h5py,opencv

To install these packages

pip install tensorflow==2.2.0,mtcnn,cmake,h5py,opencv-contrib-python

Implementations:

Here we use face-recognition module, Built using dlib’s state-of-the-art face recognition built with deep learning. The model has an accuracy of 99.38% on the Labeled Faces in the Wild benchmark. which uses MTCNN module to detect faces in an image and then it is going to recognize faces by comparing a known face with an unknown face.

Here the model in the face-recognition module gets trained on basis of “how to compare two faces of similar features”. Not on the basis of training the images of different classes.

For Example

Known Image(Robert Downey Jr) Unknown ImageUnknown Image

This Module compares the known image with an unknown image by determining similar features, It returns Boolean values[True or False]

Code:

The below code is to load the image file and bypassing the image to the face_location method, it returns the face locations. This is how we can load the image file

import face_recognition

image = face_recognition.load_image_file("my_picture.jpg")
face_locations = face_recognition.face_locations(image)

The Below code is for encoding the known image and unknown image, Since the face_encoding method returns multiface’s encodings in a single image as an array, Here for testing, we use a single face in an image. That’s why we passed index 0.

Then we pass the encodings in the compare_face method, which is used to compare the features(similarity), It returns True or False.

import face_recognition
known_image = face_recognition.load_image_file("biden.jpg")
unknown_image = face_recognition.load_image_file("unknown.jpg")

biden_encoding = face_recognition.face_encodings(known_image)[0]
unknown_encoding = face_recognition.face_encodings(unknown_image)[0]

results = face_recognition.compare_faces([biden_encoding], unknown_encoding)

So, We can able to recognize faces by comparing images…,

Code Reference:https://github.com/SriVinayagaBarathan/Face-Recognition-By-comparing-Python-Module-/blob/main/Face_Recognition_test.ipynb

For any queries–Reach out

linked-in:https://www.linkedin.com/in/srivinayagabarathan/

github: https://github.com/SriVinayagaBarathan

Leave a Comment

Your email address will not be published. Required fields are marked *