Smart Mood Tracker
& Lie Detector Architecture
A full-stack, AI-integrated biometric health and security monitoring system engineered by SMK Dato' Penggawa Timur students.
Press keys 1–11 anytime to jump directly to any engineering module.
System Capabilities
Advanced biometric tracking and data analysis seamlessly integrated.
Real-Time Pulse
Live BPM tracking using the MAX30102 sensor connected via I2C on the Raspberry Pi 5 for high-accuracy readings.
Live AI Camera Feed
MJPEG streaming with complex visual AI overlay for face mapping and hand tracking to analyze physical stress.
Deception Detection
Multi-factor lie detection algorithm integrating pulse spikes, facial visual stress, and hand positioning logic.
42-Question Assessment
Engaging emoji-based behavioral and emotional evaluation with automated timer and grading systems.
Data Dashboard
Comprehensive dashboard to view all submissions, sensor history, and access full video replays of sessions.
Secure Access
Multi-Auth login supporting Email, Google, GitHub, and Facebook OAuth alongside 2FA verification.
System Architecture
A dual-server architecture operating over a local network.
Media Streaming & Recording Pipeline
How live video and two-way voice are captured, delivered, and displayed.
1. FFmpeg Pipeline
FFmpeg acts as the multimedia engine in our pipeline for capturing live streams, extracting audio tracks, and transcoding recorded sessions into compressed .mp4 archives.
2. OpenH264 Codec
openh264-1.8.0-win64.dll bridges OpenCV H.264 licensing gaps so webcam recordings encode efficiently into standard MP4 files locally with zero external server dependency.
Behavioral Analysis Algorithm
60/40 Stress Fusion & 50/50 Physical + Random Forest Deception Scoring.
1. Stress Score Calculation
- Pulse Stress (40% Weight): Raw BPM from MAX30102 minus 60 BPM baseline, scaled to 100% (140 BPM max).
- Visual Stress (60% Weight): Camera facial tension metrics (rigid jaw, tight eyebrows).
2. Deception Score Calculation
- Heart Rate & Spikes: BPM > 115 (+40), BPM > 95 (+20), or +20% sudden jump (+40).
- Hand Kinesics: Covering mouth (+50), touching face (+30).
- ML Fusion:
(Physical Score × 0.5) + (ML Score × 0.5).
Key Engineering Challenges & Solutions
1. Sensor Movement Noise Fix (Rolling-Average Filter)
Solution: 4-second rolling-average filter in Python to smooth microscopic finger wiggles before BPM computation.
if len(IR_HISTORY) > 5:
avg = sum([v for t, v in IR_HISTORY]) / len(IR_HISTORY)
if ir < avg * 0.998 and (avg - ir) > 50 and nav_t - LAST_BEAT_TIME > 0.40:
delta = nav_t - LAST_BEAT_TIME
new_bpm = 60.0 / delta
2. Real-Time Data Synchronization Script
Solution: Custom UTC-timestamped synchronization payload fusing camera visual stress and MAX30102 pulse readings.
payload = {
"bpm": bpm,
"stress": stress_status,
"deception_score": final_score,
"visual_stress": VISUAL_STRESS
}
history.append({"ts": datetime.utcnow().isoformat() + "Z", **payload})
3. Preventing Overfitting via Normalization
Solution: Dynamic personal baseline normalization using the user's last 10 readings, flagging only +20% relative spikes.
if len(history) > 10:
past_bpms = [h['bpm'] for h in history[-10:] if isinstance(h.get('bpm'), int)]
if past_bpms and bpm > (sum(past_bpms) / len(past_bpms)) * 1.20:
deception_score += 30
Defending Our Code
Hand-engineered I2C bit-shifting, daemon threading, MJPEG generators, and WSGI-safe polling.
Custom I2C Bit-Shifting (MAX30102)
data = self.bus.read_i2c_block_data(self.address, 0x07, 6)
red = ((data[0] << 16) | (data[1] << 8) | data[2]) & 0x03FFFF
ir = ((data[3] << 16) | (data[4] << 8) | data[5]) & 0x03FFFF
Non-Blocking 100Hz Daemon Thread
sensor_thread = threading.Thread(target=sensor_loop, daemon=True)
sensor_thread.start()
# Samples I2C at 100Hz without blocking Flask
Custom MJPEG Multipart Generator
ret, buffer = cv2.imencode('.jpg', frame)
yield (b'--frame\r\nContent-Type: image/jpeg\r\n\r\n'
+ buffer.tobytes() + b'\r\n')
Thread-Safe JSON Lock & Validation
with db_lock:
if len(answers) != 40:
return jsonify({"error": "Incomplete"}), 400
MAX30102 Sensor Report
Measures heart rate and blood oxygen via Photoplethysmography (PPG) using Red and Infrared LEDs to capture pulsing blood volume changes in capillaries.
Official MAX30102 DocsThe Live Monitor Dashboard
- AI Input Optimization: Live AI processes only video + pulse to stay lag-free on Raspberry Pi 5.
- Baseline Calibration: Control questions establish resting heart rate & facial baseline.
- Real-Time Inference: Displays live camera, rolling BPM graph, and instant Truth/Deception status.
Psychological Analysis (DASS-42)
Clinically validated 42-item assessment for Depression, Anxiety, and Stress (0–3 severity scale).
DASS-42 SEVERITY CUTOFFS
Clinical Source| Severity Level | Depression (0–42) | Anxiety (0–42) | Stress (0–42) |
|---|---|---|---|
| Normal | 0 – 9 | 0 – 7 | 0 – 14 |
| Mild | 10 – 13 | 8 – 9 | 15 – 18 |
| Moderate | 14 – 20 | 10 – 14 | 19 – 25 |
| Severe | 21 – 27 | 15 – 19 | 26 – 33 |
| Extremely Severe | 28+ | 20+ | 34+ |
🔴 Critical
Any scale reaches Severe or Extremely Severe.
🟡 Warning
Highest scale reaches Moderate.
🟢 Stable
Highest scale reaches Mild.
🌟 Excellent
All three scales are Normal.
Machine Learning AI Engine
Custom-trained Random Forest Classifier built on 40,986 facial expression samples.
40,986 Data Points
Trained on Real-Life Deception Detection & FER-2013 Kaggle datasets to recognize subtle micro-expressions.
Core ML Stack
Scikit-Learn Random Forest, Google MediaPipe (468 3D facial landmarks), Pandas, and OpenCV.
Training Output
> IMAGES PROCESSED: 40,986
> TRAINING RANDOM FOREST...
> MODEL READY FOR INFERENCE.
Project Deep Dive
1. Mediapipe Visual Stress Detection
Continuously maps micro-expressions via Face Mesh, analyzing facial rigidity and spontaneous cues to compute real-time Visual Stress.
2. Mediapipe Hand Tracking
Maps palm and digit coordinates so facial-touching or mouth-covering gestures dynamically elevate the deception risk profile.
3. MAX30102 Pulse Integration
Interfaced with Raspberry Pi 5 via I2C using PPG to capture pulse data and trigger alerts on >20% baseline deviations.
4. Tri-Factor Deception Algorithm
Fuses cardiovascular anomalies, facial stress markers, and defensive hand gestures into a real-time 0–100 risk score.
5. School-Wide Analytics & Multi-Auth
Supports Google/GitHub/Facebook OAuth + 2FA OTP, local LLM copilot, FFmpeg MP4 replay, and 35 class-specific counselor dashboards.