A complete face detection and recognition web application built with Flask backend and HTML/JavaScript/Tailwind CSS frontend. The application supports face registration, real-time recognition, and webcam integration.
- Face Detection: Detect faces in uploaded images or webcam feed using OpenCV
- Face Registration: Register new faces with names for future recognition
- Face Recognition: Recognize registered faces with confidence scores
- Real-time Processing: Live webcam feed with continuous face recognition
- Image Upload: Support for uploading images for registration and recognition
- Modern Design: Clean, responsive UI built with Tailwind CSS
- Dual Panels: Separate sections for registration and recognition
- Live Video Feed: Real-time webcam integration
- Visual Feedback: Face bounding boxes with name labels
- Status Messages: Real-time feedback for all operations
- Registered Faces Gallery: Visual display of all registered faces
- RESTful API: Well-structured Flask backend with clear endpoints
- CORS Support: Cross-origin requests enabled for frontend-backend communication
- Data Persistence: Face encodings stored in pickle format
- Error Handling: Comprehensive error handling and user feedback
- Responsive Design: Works on desktop and mobile devices
face-recognition-app/
βββ src/
β βββ data/ # Face encodings storage
β βββ database/ # SQLite database (optional)
β βββ models/ # Database models
β βββ routes/ # Flask route blueprints
β β βββ face_recognition.py # Face recognition API endpoints
β β βββ user.py # User management routes
β βββ static/ # Frontend files
β β βββ index.html # Main HTML file
β β βββ app.js # JavaScript functionality
β β βββ test_*.jpg # Test images
β βββ main.py # Flask application entry point
βββ venv/ # Python virtual environment
βββ requirements.txt # Python dependencies
βββ README.md # This file
- Python 3.8 or higher
- pip (Python package installer)
- A modern web browser with webcam support
-
Extract the project files
unzip face-recognition-app.zip cd face-recognition-app -
Create and activate virtual environment
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Python dependencies
pip install -r requirements.txt
-
Run the application
cd src python main.py -
Access the application Open your web browser and navigate to:
http://localhost:5000
- Enter Person Name: Type the name of the person you want to register
- Choose Input Method:
- Start Camera: Use webcam to capture a live photo
- Upload Image: Select an image file from your device
- Capture & Register: Click the button to register the face
- Verification: Check the "Registered Faces" section to confirm registration
- Choose Recognition Method:
- Live Recognition: Start webcam for real-time face recognition
- Upload & Recognize: Upload an image for recognition
- View Results:
- Face bounding boxes appear around detected faces
- Names and confidence scores are displayed
- Recognition results are listed below the image
- View Registered Faces: Scroll down to see all registered faces
- Clear All: Use the "Clear All" button to remove all registered faces
- Status Messages: Monitor the status bar for operation feedback
- POST
/api/face/detect - Body:
{"image": "base64_encoded_image"} - Response:
{"success": true, "faces": [...], "count": 1}
- POST
/api/face/register - Body:
{"name": "Person Name", "image": "base64_encoded_image"} - Response:
{"success": true, "message": "Face registered successfully"}
- POST
/api/face/recognize - Body:
{"image": "base64_encoded_image"} - Response:
{"success": true, "faces": [...], "count": 1}
- GET
/api/face/registered - Response:
{"success": true, "registered_names": [...], "count": 2}
- POST
/api/face/clear - Response:
{"success": true, "message": "All registered faces cleared"}
- Face Detection: OpenCV Haar Cascade Classifier
- Face Recognition: Custom feature extraction and comparison
- Data Storage: Pickle files for face encodings
- API Design: RESTful endpoints with JSON responses
- Error Handling: Comprehensive error catching and user feedback
- Framework: Vanilla JavaScript with Tailwind CSS
- Webcam Access: getUserMedia API for camera integration
- Image Processing: Canvas API for image manipulation
- Real-time Updates: Continuous recognition with visual feedback
- Responsive Design: Mobile-friendly interface
- Detection: Haar Cascade detects face regions
- Feature Extraction: Resize and normalize face regions
- Encoding: Convert to grayscale and flatten as feature vector
- Comparison: Normalized correlation coefficient for matching
- Threshold: Configurable similarity threshold for recognition
- Chrome: Full support (recommended)
- Firefox: Full support
- Safari: Full support
- Edge: Full support
Note: Webcam functionality requires HTTPS in production environments.
-
Camera not working
- Ensure browser has camera permissions
- Check if camera is being used by another application
- Try refreshing the page
-
Face not detected
- Ensure good lighting conditions
- Face should be clearly visible and front-facing
- Try different angles or distances
-
Recognition accuracy issues
- Register faces with clear, well-lit images
- Use consistent lighting conditions
- Register multiple angles of the same person
-
Installation issues
- Ensure all system dependencies are installed
- Check Python version compatibility
- Verify virtual environment activation
- Use well-lit environments for better detection
- Register faces with clear, front-facing photos
- Avoid extreme angles or poor lighting
- Clear browser cache if experiencing issues
- Backend: Add new routes in
src/routes/face_recognition.py - Frontend: Extend functionality in
src/static/app.js - Styling: Modify Tailwind classes in
src/static/index.html
- Face encodings are stored locally in pickle files
- No face images are permanently stored (only encodings)
- CORS is enabled for development (configure for production)
- Consider HTTPS for production deployment
This project is provided as-is for educational and development purposes.
For issues or questions:
- Check the troubleshooting section
- Verify all dependencies are installed correctly
- Ensure proper browser permissions for camera access
Enjoy using your Face Recognition Web Application! π Give me a star and follow me π