This repository contains a face recognition and search system built with Python. The application allows for the detection, encoding, and storage of facial data in a MongoDB database. It supports searching for similar faces based on the stored data and provides a graphical user interface (GUI) to manage the face search and display results.
- Face detection and recognition: Extract faces from images, encode them, and save unique faces to a database.
- Database management: Stores face encodings and image metadata using MongoDB.
- Face search functionality: Find similar faces from the database using face encoding comparison.
- Graphical User Interface (GUI): Built with Tkinter for managing face data and searching faces. (to be updated)
- Logging: Application logs all key actions and events to a log file and console.
.
├── database.py # Handles MongoDB operations and face encoding storage/retrieval
├── face_detection.py # Processes images, detects faces, and manages face data storage
├── gui.py # GUI implementation for searching and displaying face data
├── main.py # Entry point for running the GUI application
├── search.py # Contains functions to search faces by ID
├── images/ # Folder where input images are stored
└── unique_faces/ # Folder where unique face images are saved
Make sure you have the following libraries installed before running the code:
pymongo
: For database operations.face_recognition
: For facial recognition and encoding.opencv-python
: For image processing.pillow
: For handling images in the GUI.tkinter
: For GUI development (comes pre-installed with Python).numpy
: For handling face encoding data.
Install all dependencies via pip
:
pip install pymongo face_recognition opencv-python pillow numpy
or
pip install -r requirements.txt
Ensure that MongoDB is running on localhost:27017
and the database face_recognition_db
is created. The face encodings and metadata will be stored in the faces_collection
.
To extract and save unique faces from images:
- Place your images in the
images/
folder. - Run the following script to detect faces and store them in MongoDB:
python face_detection.py
This will:
- Extract faces from the images.
- Store each unique face's encoding and associated metadata in MongoDB.
- Save each detected face as an image in the
unique_faces/
folder.
To launch the face search interface:
python main.py
The GUI will display all unique faces. You can select a face and search for its occurrences in the images.
- Select a face: Click on a face from the GUI.
- Search for occurrences: Click the "Search Selected Face" button to find where this face appears across the images.
All key operations (face detection, saving, searching) are logged into app.log
. You can change the logging level for more or less verbosity by modifying the logging.basicConfig
configuration in each file.
- Face Similarity Tolerance: Adjust the
FACE_SIMILARITY_TOLERANCE
constant indatabase.py
to change how strict the face similarity comparison is. - Unique Faces Directory: Change the folder where unique faces are saved by modifying the
unique_faces_folder
path inface_detection.py
.
- Ensure MongoDB is running and accessible at
localhost:27017
. - Make sure the required Python dependencies are installed.
- Check
app.log
for detailed error logs.
This project is licensed under the MIT License.