A FastAPI-based face recognition system that can identify faces in photos and videos. The system maintains a database of known people and can recognize them in real-time.
- Add People: Register new people with their photos
- Face Recognition: Identify people in uploaded photos
- Video Processing: Recognize faces in video files
- People Management: View, manage, and delete registered people
- REST API: Full RESTful API with Swagger documentation
- Web Interface: User-friendly HTML interface for testing
- Python 3.8+
- OpenCV
- face-recognition library
- FastAPI
- See
requirements.txtfor full list
- Clone the repository:
git clone <repository-url>
cd face-recognition-api- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Navigate to the API directory:
cd API/src- Start the server:
python main.pyThe server will start on http://localhost:8000
Open test_page.html in your web browser to access the user interface.
- Add Person: Upload a photo with a person's name to register them
- Recognize Photo: Upload a photo to identify people in it
- Recognize Video: Upload a video file to identify people throughout the video
- View Database: See all registered people
- Statistics: View system statistics
POST /api/person/add- Add new personGET /api/person/list- List all peopleGET /api/person/{id}- Get specific person infoDELETE /api/person/{id}- Delete person
POST /api/person/recognize- Recognize faces in photoPOST /api/video/recognize- Recognize faces in videoPOST /api/person/recognize-base64- Recognize faces in base64 image
GET /- API health checkGET /api/stats- System statistics
When the server is running, visit:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
API/
├── src/
│ └── main.py # Main application file
├── uploads/ # Uploaded photos storage
├── persons_data.csv # Database file
├── test_page.html # Web interface
├── debug_video.html # Debug interface for video
└── requirements.txt # Python dependencies
When processing videos:
- Frame Interval: Process every Nth frame (default: 15)
- Lower values = more accurate but slower
- Higher values = faster but may miss short appearances
- Key Frames: Up to 10 annotated frames are returned
- Results: Includes timestamps and confidence scores
Key settings in main.py:
CSV_FILE: Database file locationUPLOAD_DIR: Directory for uploaded filesframe_interval: Video processing interval
-
"No module named 'face_recognition'"
- Make sure you've installed all requirements
- On some systems, you may need to install dlib first
-
Video processing is slow
- Increase the frame_interval parameter
- Use smaller video files
- Ensure your system has adequate resources
-
Face not detected
- Ensure good lighting in photos
- Face should be clearly visible and frontal
- Photo resolution should be adequate
- Database: CSV file storing person info and face encodings
- Photos: Stored in the uploads directory
- Temporary: Video files are deleted after processing
- CORS is configured to accept all origins (
*) - restrict this in production - No authentication is implemented - add security layers for production use
- Uploaded files are stored locally - implement proper file management
Feel free to submit issues, fork the repository, and create pull requests for any improvements.
This project is open source. Please check the license file for more details.