A Spring Boot-based face recognition attendance system that uses OpenCV and JavaCV for real-time face detection and recognition. The system can mark attendance through camera capture or uploaded images.
- Real-time Face Recognition: Mark attendance using live camera feed
- Image Upload Support: Upload images for attendance marking
- Training System: Capture and train face recognition models
- Database Integration: Store attendance records in MySQL/H2 database
- Menu Image Management: Upload and view menu images per user
- RESTful API: Complete REST API for all operations
- Backend: Spring Boot 3.2.4
- Java Version: Java 17
- Computer Vision: OpenCV 4.7.0 with JavaCV 1.5.9
- Database: MySQL (production) / H2 (development)
- Face Recognition: LBPH (Local Binary Patterns Histograms) Face Recognizer
- Face Detection: Haar Cascade Classifier
- Build Tool: Maven
- Java 17 or higher
- Maven 3.6+
- MySQL 8.0+ (for production)
- Webcam (for camera-based attendance)
- Git
git clone <repository-url>
cd FaceAttendanceSystemCreate a MySQL database named faceattendance:
CREATE DATABASE faceattendance;Update src/main/resources/application.properties with your database credentials:
spring.datasource.url=jdbc:mysql://localhost:3306/faceattendance
spring.datasource.username=your_username
spring.datasource.password=your_password# Build the project
mvn clean install
# Run the application
mvn spring-boot:runThe application will start on http://localhost:8080
GET /api/face/capture/{userId}/{numImages}Captures training images for a specific user.
userId: User ID (1, 2, 3)numImages: Number of images to capture
Example: GET /api/face/capture/1/10
GET /api/face/trainTrains the face recognition model using captured images.
GET /api/face/mark-attendanceMarks attendance using live camera feed.
POST /api/face/mark-attendance-from-image
Content-Type: multipart/form-data
image: [image file]Marks attendance from an uploaded image.
POST /api/face/upload-menu-image/{userId}
Content-Type: multipart/form-data
menuImage: [image file]Uploads a menu image for a specific user.
GET /api/face/menu-images/{userId}/view/{imageName}Views a specific menu image for a user.
GET /api/face/clear-images/{userId}Clears all training images for a specific user.
The system currently supports 3 predefined users:
- User ID 1: Anurag Singh
- User ID 2: Rohit Singh
- User ID 3: Virat Kohli
src/
βββ main/
β βββ java/com/org/
β β βββ controller/
β β β βββ FaceController.java # REST API endpoints
β β βββ service/
β β β βββ FaceService.java # Face recognition logic
β β βββ model/
β β β βββ Attendance.java # Attendance entity
β β βββ repository/
β β β βββ AttendanceRepository.java # Data access layer
β β βββ FaceAttendanceSystemApplication.java
β βββ resources/
β βββ application.properties # Configuration
β βββ haarcascade_frontalface_alt.xml # Face detection model
β βββ trained_faces/
β βββ lbph_model.xml # Trained face recognition model
- Start the application
- Capture training images for each user using
/api/face/capture/{userId}/{numImages} - Train the model using
/api/face/train
- Camera Method: Use
/api/face/mark-attendancefor real-time attendance - Image Method: Upload an image using
/api/face/mark-attendance-from-image
- Upload menu images using
/api/face/upload-menu-image/{userId} - View menu images using
/api/face/menu-images/{userId}/view/{imageName} - Clear training data using
/api/face/clear-images/{userId}
CREATE TABLE attendance (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
date DATE NOT NULL,
time TIME NOT NULL,
UNIQUE KEY unique_user_date (user_id, date)
);- Uses LBPH (Local Binary Patterns Histograms) for face recognition
- Haar Cascade Classifier for face detection
- Confidence threshold: < 98.0 for camera, < 80 for images
- Face images resized to 160x160 pixels for consistency
- Training images:
C:/training_images/user{userId}/ - Menu images:
C:/menu_images/user{userId}/ - Model file:
src/main/resources/trained_faces/lbph_model.xml
- One attendance record per user per day
- Automatic duplicate prevention
- Timestamp tracking for each attendance
-
Camera Access Error
- Ensure webcam is connected and not used by other applications
- Check camera permissions
-
Model Not Found Error
- Train the model first using
/api/face/train - Ensure training images exist in
C:/training_images/
- Train the model first using
-
Database Connection Error
- Verify MySQL is running
- Check database credentials in
application.properties - Ensure database
faceattendanceexists
-
Face Not Recognized
- Ensure sufficient training images (recommended: 10-20 per user)
- Check lighting conditions
- Verify face is clearly visible and frontal
- The system stores images locally on the server
- Consider implementing authentication for production use
- Add input validation for file uploads
- Implement proper error handling and logging
- Web-based UI for easier interaction
- User authentication and authorization
- Attendance reports and analytics
- Multi-face detection support
- Cloud storage integration
- Mobile app support
- Real-time notifications
- Advanced face recognition models (Deep Learning)
This project is licensed under the MIT License.
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
For support and questions, please open an issue in the repository.
Note: This system requires a webcam for camera-based attendance marking. Ensure your system has proper camera access permissions.