This project focuses on the facial comparison in 2 images.
The application takes two images of people as inputs and tells us whether they are the same.
The Python libraries used for this project are openCV and face recognition, and the GUI is made using the Tkinter framework.
A function that utilizes the filedialog library from the tkinter framework is used to select the input images that need to be compared. The location of the selected image is stored and returned by the function when it is called.
The two images are selected utilizing the above-discussed function. The imread function loads the selected images as Numpy arrays from their respective file paths. The cvtColor function is used to change the color format of the selected images to RGB (the standard color format used by most image processing libraries including face_recognition).
The face_encodings function from the fromface_recognition library does embedding to capture the unique features of the face in a 128-dimensional vector. This vector is robust to changes like lighting, pose, and facial expression, making it suitable for face recognition tasks.
Note: [0] at the end of the line of the image encoding code accesses the first face's embedding, assuming the image contains exactly one face.
The compare_faces function calculates the distance between the two vectors of the images to see if the faces match. The function internally uses the Euclidean distance (or L2 norm) to calculate the difference between the given face encoding and each known encoding.
By default, a face is considered a match if the computed distance is less than 0.6. If we increase the threshold it will decrease false negatives and increase false positives but if we decrease the threshold the inverse will occur.
The messagebox from the tkinter library displays pop-up dialogs that show the results of the face comparison.
Note: It is checked if result[0] is true to determine if the faces match. Since the result is a list we check the the first element of that list.
cv2.imshow is utilized the display the two input images after the result is shown.
cv2.waitKey(0) stops the program till the user presses a key. Once a key is pressed, the program continues execution (e.g., closing the windows).
If any error occurs during the process (e.g., images not loaded properly, no faces detected, etc.), an error message in a pop-up window with the title "Error" and a description of the issue will be displayed.
The main application window is made using tkinter's Tk() class, this is the root window where all widgets (e.g., buttons, labels) are added.
The application is successfully able to take in two input images and compare faces from those images to confirm if they are the same person. The demo video is uploaded in the resources section as well please check it to see how the app works.
There are no datasets linked
There are no datasets linked