- Overview
- Technical Architecture
- Requirements
- Common Issues and Troubleshooting
- Learning Resources
- Installation
- Usage
- Technical Implementation
- Project Structure
- Contributing
- License
- Contact
- Recognition accuracy may decrease in poor lighting conditions.
- Requires a high-quality webcam for optimal performance.
- Limited to local storage unless MongoDB is configured.
InstaMatch is a sophisticated facial recognition attendance system built with OpenCV. It automatically records attendance with high accuracy by capturing and processing faces from multiple angles and lighting conditions, storing records in both CSV files and MongoDB.
- Face Detection: Multi-angle detection using cascades for frontal and profile faces
- Face Recognition: LBPH (Local Binary Patterns Histograms) face recognition with optimized parameters
- Image Processing: Histogram equalization, rotation normalization, and perspective transforms
- Data Augmentation: Runtime generation of training variations from single reference images
- Local Storage: Date-stamped CSV files in the attendance directory
- Database: MongoDB integration for scalable attendance records with confidence metrics
- Environment Configuration: Configurable database connection via
.env
- Real-Time Processing: Optimized frame processing for low-latency recognition
- Confidence Thresholding: Adaptive recognition thresholds with stability counters
- Cooldown System: Smart duplicate prevention with configurable timing
- Error Handling: Robust exception management across the recognition pipeline
pip install -r requirements.txtRequired packages:
- opencv-python
- opencv-contrib-python
- numpy
- pymongo
- python-dotenv
- Python 3.7+
- Webcam or compatible camera device
- 4GB RAM minimum (8GB recommended)
- MongoDB (optional for database features)
- Issue: Errors while installing
opencv-pythonoropencv-contrib-python. - Solution: Ensure you have the latest version of
pip:Then retry installing the dependencies.python -m pip install --upgrade pip
- Issue: Unable to connect to MongoDB.
- Solution:
- Verify MongoDB is running on your system.
- Check the
MONGODB_URLin the.envfile for typos. - Test the connection using a MongoDB client tool.
- Issue: The application cannot access the webcam.
- Solution:
- Ensure no other application is using the webcam.
- Check if the webcam drivers are installed and up-to-date.
- Use an external USB camera if the built-in camera is not working.
- Issue: Faces are not recognized accurately.
- Solution:
- Ensure training images are clear and well-lit.
- Add more images for each person from different angles.
- Avoid using low-resolution or blurry images.
- Issue: Errors due to incompatible Python version.
- Solution: Use Python 3.7 or higher. Check your version with:
python --version
-
Clone the repository:
git clone https://github.com/NabarupDev/InstaMatch.git cd InstaMatch -
Install dependencies:
pip install -r requirements.txt
-
Configure database (optional):
- Install MongoDB if using database features
- Create/modify
.envfile with your connection details:MONGODB_URL=mongodb://localhost:27017/ DATABASE_NAME=attendance_db COLLECTION_NAME=attendance_records
-
Prepare training data:
- Create a
known_facesdirectory - Add clear face images named after each person (e.g.,
john_smith.jpg) - Best practice: Include at least 2-3 images per person from different angles
- Create a
python main.py- Add clear, well-lit face images to the
known_facesdirectory - Name each file with the person's name (e.g.,
firstname_lastname.jpg) - Restart the application to retrain the model
- Attendance is automatically saved to
attendance/attendance_YYYY-MM-DD.csv - MongoDB records include additional metadata (confidence scores, camera IDs)
- Each person is only recorded once per day regardless of multiple detections
- Face images are loaded and processed from the
known_facesdirectory - Multi-angle face detection is applied to each image
- Advanced data augmentation generates variations with different:
- Lighting conditions (brightness/contrast adjustments)
- Angles (±15° rotations in 5° increments)
- Perspectives (simulated head tilts)
- Horizontal flips (for profile recognition)
- The LBPH face recognizer is trained with these processed variations
- Video frames are captured from the webcam in real-time
- Each frame is converted to grayscale and enhanced with histogram equalization
- Faces are detected using cascades for both frontal and profile angles
- Detected faces undergo the same preprocessing as training images
- Multiple recognition attempts are made with slight rotations for angle tolerance
- Confidence thresholds and stability counters ensure reliable identification
- Attendance is marked when recognition confidence and stability criteria are met
InstaMatch/
├── attendance/ # Attendance CSV records by date
├── known_faces/ # Training images for face recognition
├── main.py # Core application logic
├── requirements.txt # Python dependencies
├── README # Project documentation
├── .env # Environment variables (MongoDB credentials)
├── .env.example # Example environment configuration
└── LICENSE # MIT License
We welcome contributions to enhance InstaMatch:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Implement your changes with appropriate tests and documentation
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Project maintainer: [email protected]
© 2025-2026 Nabarup Roy
