This repository contains the implementation of a face recognition model that I developed during my second year of college. The project utilizes Python and several powerful libraries to recognize and manipulate faces in images and real-time video feeds.
This face recognition project is built using the following key libraries:
- OpenCV: For image processing and computer vision tasks.
- NumPy: For numerical computations.
- face_recognition: For state-of-the-art face recognition with deep learning.
The model achieves an accuracy of 99.38% on the Labeled Faces in the Wild benchmark.
Detects all faces in a given image.
import face_recognition
image = face_recognition.load_image_file("your_file.jpg")
face_locations = face_recognition.face_locations(image)
- Find and Manipulate Facial Features Identifies the locations and outlines of each person's eyes, nose, mouth, and chin.
import face_recognition
image = face_recognition.load_image_file("your_file.jpg")
face_landmarks_list = face_recognition.face_landmarks(image)
- Identify Faces in Pictures Recognizes known faces from a set of images.
import face_recognition
known_image = face_recognition.load_image_file("known_person.jpg")
unknown_image = face_recognition.load_image_file("unknown_person.jpg")
known_encoding = face_recognition.face_encodings(known_image)[0]
unknown_encoding = face_recognition.face_encodings(unknown_image)[0]
results = face_recognition.compare_faces([known_encoding], unknown_encoding)
- Real-Time Face Recognition Performs face recognition in real-time using a webcam feed
import face_recognition
import cv2
video_capture = cv2.VideoCapture(0)
while True:
ret, frame = video_capture.read()
rgb_frame = frame[:, :, ::-1]
face_locations = face_recognition.face_locations(rgb_frame)
face_encodings = face_recognition.face_encodings(rgb_frame, face_locations)
for (top, right, bottom, left), face_encoding in zip(face_locations, face_encodings):
# Add your known face encodings and names here
matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
name = "Unknown"
if True in matches:
first_match_index = matches.index(True)
name = known_face_names[first_match_index]
cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)
cv2.putText(frame, name, (left + 6, bottom - 6), cv2.FONT_HERSHEY_DUPLEX, 0.5, (255, 255, 255), 1)
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video_capture.release()
cv2.destroyAllWindows()
Installation
Prerequisites Python 3.3+ or Python 2.7 macOS, Linux, or Windows (limited support) Install Required Libraries Install dlib and its Python bindings:
Installation guide for dlib
Install face_recognition library:
pip3 install face_recognition
Install other dependencies:
pip3 install numpy opencv-python
This repository contains the implementation of a face recognition model that I developed during my second year of college. The project utilizes Python and several powerful libraries to recognize and manipulate faces in images and real-time video feeds.
You can use the face_recognition
command-line tool to recognize faces in a folder of images:
face_recognition ./known_people/ ./unknown_people/
Check the examples
directory for detailed examples on how to use the library for different tasks such as face detection, facial feature extraction, and real-time recognition.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page for any open issues or to create a new one.
This project is licensed under the MIT License - see the LICENSE file for details.
Special thanks to:
- Davis King for creating dlib.
- The contributors of the face_recognition library.
- The developers of OpenCV and NumPy for their excellent tools.