An intelligent attendance management system built with R, featuring face recognition, data augmentation, and a modern Shiny web interface.
- Features
- Quick Start
- Installation
- Project Structure
- Usage Guide
- Configuration
- Troubleshooting
- Technical Details
- ✅ Face Recognition - AI-powered student identification
- ✅ Single Photo Enrollment - Works with just one photo per student
- ✅ Data Augmentation - Generates 15+ variations to improve accuracy
- ✅ SQLite Database - Lightweight, serverless data storage
- ✅ Shiny Web Interface - Modern, user-friendly GUI
- ✅ Attendance Reports - Export to CSV/Excel with visualizations
- ✅ Webcam Support - Real-time attendance marking
- ✅ Confidence Scoring - Know how certain each recognition is
source("install_dependencies.R")Time: 10-20 minutes | Internet: Required
When prompted about deep learning packages:
- Type
yfor best accuracy (requires Python installation) - Type
nfor simpler OpenCV-based approach
source("verify_installation.R")You should see: ✅ All required packages are installed!
Place photos in data/original/ folder with this format:
StudentID_FirstName_LastName.jpg
Example: 231004622_Marwan_Mesbah.jpg
Open R and run:
# Load configuration and database functions
source("R/config.R")
source("R/db_setup.R")
# Database is auto-initialized when you source db_setup.R
# Check it worked:
print_db_stats()# Add a test student
add_student(
student_id = "231004622",
name = "Marwan Mesbah",
photo_path = "data/original/231004622_Marwan_Mesbah.jpg",
email = "marwan@example.com",
department = "Computer Science"
)
# Verify enrollment
get_all_students()# Load augmentation functions
source("R/data_augmentation.R")
# Preview what augmentations will look like
preview_augmentations("data/original/231004622_Marwan_Mesbah.jpg", n = 6)
# Generate all augmented versions (creates 15 variations)
results <- augment_all_images()
# Check the augmented folder
list.files("data/augmented")shiny::runApp("app.R")- R (version 4.0 or higher) - Download
- RStudio (recommended) - Download
- Internet connection for package downloads
✅ Yes, this project runs normally on Windows!
Notes for Windows Users:
- RTools: You may need RTools installed to compile some packages (like
arroworshiny). Download RTools here. - Paths: The code uses relative paths (e.g.,
data/original), so it works automatically on both Windows and Linux. - Webcam: Shiny's webcam access works in standard browsers (Chrome/Edge) on Windows.
cd ~/Desktop/R/
git clone <repository-url> Attendance-System-Using-R
cd Attendance-System-Using-ROpen R or RStudio and run:
source("install_dependencies.R")What this installs:
- Database packages:
DBI,RSQLite - Image processing:
magick,jpeg,png,imager - Shiny framework:
shiny,shinydashboard,DT - Visualization:
ggplot2,plotly - Data tools:
dplyr,tidyr,lubridate - Export tools:
openxlsx - Optional:
keras,tensorflow(for deep learning)
Note: The script will ask if you want to install deep learning packages. Choose:
yfor best accuracy (requires Python + TensorFlow)nfor simpler setup (uses OpenCV instead)
source("verify_installation.R")Expected output:
✅ All required packages are installed!
Required Packages: 20/20
Optional Packages: 3/4
Place photos in data/original/ using this naming format:
[StudentID]_[First_Name]_[Last_Name].jpg
Examples:
231004622_Marwan_Mesbah.jpg
20230001_John_Doe.jpg
STU12345_Jane_Smith.jpg
Photo Requirements:
- ✅ Format: JPG, JPEG, or PNG
- ✅ Resolution: Minimum 640×480, recommended 1024×768
- ✅ Content: Single person, frontal face (looking at camera)
- ✅ Lighting: Good lighting, avoid heavy shadows
- ✅ Background: Any (will be ignored)
- ✅ Expression: Neutral works best
source("STEP_2_test_db.R")This creates:
- SQLite database at
db/attendance.db - Tables:
students,face_embeddings,attendance - Default configuration settings
source("STEP_3_test_augmentation.R")This will:
- Show preview of augmentations
- Generate 15 variations per photo
- Save to
data/augmented/folder
Attendance-System-Using-R/
│
├── 📂 db/ # Database folder
│ └── attendance.db # SQLite database (auto-created)
│
├── 📂 data/ # Data folder
│ ├── original/ # ⭐ Put student photos here
│ │ └── StudentID_Name.jpg # Format: ID_FirstName_LastName.jpg
│ ├── augmented/ # Auto-generated variations
│ └── temp/ # Temporary uploads
│
├── 📂 models/ # Pre-trained model weights
│ └── facenet_keras.h5 # (Downloaded when needed)
│
├── 📂 R/ # R source code
│ ├── config.R # ⚙️ System configuration
│ ├── db_setup.R # 💾 Database initialization
│ ├── data_augmentation.R # 🔄 Image augmentation
│ ├── face_detection.R # 👤 Face detection (coming soon)
│ ├── face_model.R # 🧠 Face recognition model (coming soon)
│ ├── enrollment.R # ✍️ Student enrollment (coming soon)
│ ├── mark_attendance.R # ✅ Attendance marking (coming soon)
│ └── reports.R # 📊 Reports & analytics (coming soon)
│
├── 📂 logs/ # System logs
│
├── 📄 app.R # 🌐 Shiny web application (coming soon)
│
├── 📄 install_dependencies.R # 📦 Package installer
├── 📄 verify_installation.R # ✔️ Installation checker
│
├── 📄 README.md # This file
├── 📄 IMPLEMENTATION_PLAN.md # Technical implementation plan
├── 📄 QUICK_START.md # Quick start guide
└── 📄 WORKFLOW_OVERVIEW.md # System workflow explanation
Method 1: Through Shiny App (Coming Soon)
- Run
shiny::runApp("app.R") - Go to "Enrollment" tab
- Upload photo and enter student details
- Click "Enroll Student"
Method 2: Batch Enrollment from Folder
# 1. Place photos in data/original/ with format: StudentID_Name.jpg
# 2. Run:
source("R/enrollment.R")
bulk_enroll_from_folder("data/original/")Method 3: Manual Enrollment
source("R/db_setup.R")
add_student(
student_id = "231004622",
name = "Marwan Mesbah",
photo_path = "data/original/231004622_Marwan_Mesbah.jpg",
email = "marwan@example.com",
department = "Computer Science"
)Through Shiny App: (Coming Soon)
- Go to "Mark Attendance" tab
- Click "Capture from Webcam" OR upload photo
- System detects and recognizes faces
- Attendance automatically recorded
Programmatically:
source("R/mark_attendance.R")
# Mark attendance from photo
mark_attendance_from_photo("path/to/photo.jpg")
# Mark attendance from webcam
mark_attendance_from_webcam()Through Shiny App: (Coming Soon)
- Go to "Reports" tab
- Select date range and filters
- View statistics and charts
- Export to CSV/Excel
Programmatically:
source("R/reports.R")
# Get attendance for a specific date
get_attendance_by_date("2024-11-23")
# Get attendance for a student
get_student_attendance("231004622")
# Calculate attendance percentage
get_attendance_percentage("231004622")
# Export to CSV
export_attendance_csv("attendance_report.csv")Edit R/config.R to customize system behavior:
# Face Recognition Settings
FACE_MATCH_THRESHOLD <- 0.6 # Lower = stricter (0.0-1.0)
FACE_SIZE <- c(160, 160) # Image size for processing
# Data Augmentation
AUGMENTATION_COUNT <- 15 # Number of variations per photo
# Model Selection
MODEL_TYPE <- "facenet" # Options: "facenet", "vggface", "opencv_lbph"
# Database
DB_PATH <- "db/attendance.db" # Database location
# Enable/Disable Features
ENABLE_WEBCAM <- TRUE # Webcam support
ENABLE_LOGGING <- TRUE # Detailed logging
DEV_MODE <- FALSE # Development mode (extra debug info)Problem: Package installation fails
Solutions:
# Try installing packages individually
install.packages("DBI")
install.packages("RSQLite")
install.packages("magick")
# etc...
# Or run verification to see what's missing
source("verify_installation.R")Problem: "Error in library(DBI) : there is no package called 'DBI'"
Solution: Package not installed. Run:
install.packages("DBI")Problem: "Database is locked"
Solution: Close all connections and reset:
source("R/db_setup.R")
reset_database(confirm = TRUE) # WARNING: Deletes all dataProblem: Database corrupted
Solution:
# Backup first
cp db/attendance.db db/attendance_backup.db
# Reset database
Rscript -e "source('R/db_setup.R'); reset_database(confirm=TRUE)"Problem: "No faces detected"
Solutions:
- Ensure photo has good lighting
- Face should be clearly visible and frontal
- Check photo format (JPG/PNG)
- Try adjusting
FACE_DETECTION_THRESHOLDin config
Problem: "Low confidence matches"
Solutions:
- Adjust
FACE_MATCH_THRESHOLD(lower value = stricter) - Ensure enrollment photo quality
- Generate more augmented images
- Consider collecting 2-3 photos per student
Problem: "magick not loading" on Linux
Solution:
# Install ImageMagick system library
sudo apt-get update
sudo apt-get install libmagick++-dev
# Reinstall R package
Rscript -e "install.packages('magick')"students table:
CREATE TABLE students (
id INTEGER PRIMARY KEY AUTOINCREMENT,
student_id TEXT UNIQUE NOT NULL,
name TEXT NOT NULL,
photo_path TEXT,
enrollment_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
email TEXT,
phone TEXT,
department TEXT,
status TEXT DEFAULT 'active'
);face_embeddings table:
CREATE TABLE face_embeddings (
id INTEGER PRIMARY KEY AUTOINCREMENT,
student_id TEXT NOT NULL,
embedding_vector BLOB NOT NULL, -- 128D face embedding
is_augmented INTEGER DEFAULT 0, -- 0=original, 1=augmented
created_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (student_id) REFERENCES students(student_id)
);attendance table:
CREATE TABLE attendance (
id INTEGER PRIMARY KEY AUTOINCREMENT,
student_id TEXT NOT NULL,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
confidence_score REAL, -- 0.0 to 1.0
status TEXT DEFAULT 'present',
photo_path TEXT,
FOREIGN KEY (student_id) REFERENCES students(student_id)
);- Face Detection - OpenCV Haar Cascades or DNN
- Face Alignment - Crop and normalize to 160×160
- Embedding Generation - Convert to 128D vector using FaceNet
- Similarity Matching - Cosine similarity or Euclidean distance
- Threshold Filtering - Accept if similarity > threshold
- Record Attendance - Save with confidence score
- Geometric: Rotation (±15°), scaling (90-110%), flipping
- Photometric: Brightness (±20%), contrast (±15%), saturation (±10%)
- Noise: Gaussian noise, subtle blur
- Implementation Plan: See
IMPLEMENTATION_PLAN.mdfor detailed technical documentation - Quick Start: See
QUICK_START.mdfor step-by-step setup guide - Workflow: See
WORKFLOW_OVERVIEW.mdfor system architecture
- Project structure and organization
- Database schema and initialization
- Configuration system
- Data augmentation pipeline
- Package installation system
- Installation verification
- Face detection module
- Face recognition model integration
- Student enrollment system
- Attendance marking system
- Reporting and analytics
- Shiny web interface
- Batch attendance processing
- Email notifications
- Advanced analytics dashboard
- Mobile app integration
- Multi-camera support
This is a custom project for educational purposes. Feel free to modify and extend for your needs!
Free to use and modify for educational and personal purposes.
- Photo Quality Matters: Good lighting and clear faces improve accuracy significantly
- Multiple Photos: If possible, collect 3-5 photos per student in different conditions
- Threshold Tuning: Adjust
FACE_MATCH_THRESHOLDbased on your accuracy needs - Regular Backups: Backup
db/attendance.dbregularly - Test First: Always test with a small group before full deployment
For issues or questions:
- Check the troubleshooting section above
- Review
QUICK_START.mdfor setup help - Check
IMPLEMENTATION_PLAN.mdfor technical details
Built with ❤️ using R and Shiny