Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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.

Notifications You must be signed in to change notification settings

starsentry/face_attendance_system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Face Attendance System

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.

πŸš€ Features

  • 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

πŸ› οΈ Technology Stack

  • 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

πŸ“‹ Prerequisites

  • Java 17 or higher
  • Maven 3.6+
  • MySQL 8.0+ (for production)
  • Webcam (for camera-based attendance)
  • Git

πŸ”§ Installation & Setup

1. Clone the Repository

git clone <repository-url>
cd FaceAttendanceSystem

2. Database Setup

Create a MySQL database named faceattendance:

CREATE DATABASE faceattendance;

3. Configuration

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

4. Build and Run

# Build the project
mvn clean install

# Run the application
mvn spring-boot:run

The application will start on http://localhost:8080

πŸ“š API Documentation

Face Recognition Endpoints

1. Capture Training Images

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

2. Train Model

GET /api/face/train

Trains the face recognition model using captured images.

3. Mark Attendance (Camera)

GET /api/face/mark-attendance

Marks attendance using live camera feed.

4. Mark Attendance (Image Upload)

POST /api/face/mark-attendance-from-image
Content-Type: multipart/form-data

image: [image file]

Marks attendance from an uploaded image.

5. Upload Menu Image

POST /api/face/upload-menu-image/{userId}
Content-Type: multipart/form-data

menuImage: [image file]

Uploads a menu image for a specific user.

6. View Menu Image

GET /api/face/menu-images/{userId}/view/{imageName}

Views a specific menu image for a user.

7. Clear Training Images

GET /api/face/clear-images/{userId}

Clears all training images for a specific user.

πŸ‘₯ User Management

The system currently supports 3 predefined users:

  • User ID 1: Anurag Singh
  • User ID 2: Rohit Singh
  • User ID 3: Virat Kohli

πŸ“ Project Structure

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

πŸ”„ Workflow

1. Initial Setup

  1. Start the application
  2. Capture training images for each user using /api/face/capture/{userId}/{numImages}
  3. Train the model using /api/face/train

2. Marking Attendance

  • Camera Method: Use /api/face/mark-attendance for real-time attendance
  • Image Method: Upload an image using /api/face/mark-attendance-from-image

3. Management

  • 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}

πŸ“Š Database Schema

Attendance Table

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)
);

🎯 Key Features Explained

Face Recognition Algorithm

  • 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

File Storage

  • Training images: C:/training_images/user{userId}/
  • Menu images: C:/menu_images/user{userId}/
  • Model file: src/main/resources/trained_faces/lbph_model.xml

Attendance Logic

  • One attendance record per user per day
  • Automatic duplicate prevention
  • Timestamp tracking for each attendance

🚨 Troubleshooting

Common Issues

  1. Camera Access Error

    • Ensure webcam is connected and not used by other applications
    • Check camera permissions
  2. Model Not Found Error

    • Train the model first using /api/face/train
    • Ensure training images exist in C:/training_images/
  3. Database Connection Error

    • Verify MySQL is running
    • Check database credentials in application.properties
    • Ensure database faceattendance exists
  4. Face Not Recognized

    • Ensure sufficient training images (recommended: 10-20 per user)
    • Check lighting conditions
    • Verify face is clearly visible and frontal

πŸ”’ Security Considerations

  • 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

πŸš€ Future Enhancements

  • 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)

πŸ“ License

This project is licensed under the MIT License.

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

πŸ“ž Support

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.

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages