Skip to content

nttssv/posture_monitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧘 Posture Monitor

An offline, privacy-focused desktop application that uses AI to monitor your sitting posture in real-time and alerts you when you slouch.

Good Posture vs Bad Posture

✨ Features

  • πŸ”’ 100% Offline & Private: All processing happens locally on your device
  • πŸ€– AI-Powered Detection: Uses TensorFlow.js MoveNet for real-time pose tracking
  • πŸ“ Personal Calibration: Adapts to your unique body type and sitting style
  • ⚠️ Smart Alerts: Audio alerts after 3 seconds of bad posture
  • πŸ“Š Session Statistics: Track good vs. bad posture time
  • πŸŽ“ Personalized Training: Create a custom AI model trained on YOUR posture
  • 🎨 Modern UI: Beautiful interface with live webcam feed and skeleton overlay

πŸš€ Quick Start

Prerequisites

  • Node.js (v16 or higher) - Download here
  • macOS (tested on macOS 10.15+) or Windows/Linux
  • Webcam with permissions granted

Installation

  1. Clone or download this repository

    git clone git@github.com:nttssv/posture_monitor.git
    cd posture_monitor
  2. Install dependencies

    npm install

    Note: On first run, TensorFlow.js will download the AI model (~12MB). This requires internet connection only once. After that, the app works completely offline.

  3. Add alert sound (included: beep.mp3)

    The repository includes a beep sound file. If you want to customize it, replace beep.mp3 with your own audio file (1-2 seconds recommended).

  4. Run the application

    npm start

That's it! The app will launch automatically.

πŸ“– How to Use

First Time Setup

  1. Grant Camera Permission: When prompted, allow the app to access your webcam
  2. Wait for AI Model: "Loading AI model..." will appear (10-30 seconds)
  3. Position Yourself: Sit in front of the webcam in good lighting
  4. Quick Calibration: Click "Calibrate Posture" while sitting with good posture

You're now monitoring your posture!

Understanding Posture

Good Posture Checklist:

  • βœ“ Head aligned over shoulders
  • βœ“ Shoulders relaxed and level
  • βœ“ Straight spine (natural curve)
  • βœ“ 90Β° angle at hips and knees
  • βœ“ Feet flat on floor

Common Bad Posture Mistakes:

  • βœ— Forward head ("tech neck")
  • βœ— Rounded shoulders
  • βœ— Curved/hunched spine
  • βœ— Leaning to one side

Using the Interface

Status Indicator (top-right overlay):

  • βœ… Green = Good Posture
  • ⚠️ Red = Bad Posture (with pulsing animation and audio alert)

Control Panel:

  • Calibrate Posture: Quick baseline setup (5 seconds)
  • Start Training: Create personalized AI model (2-3 minutes)
  • Sound Alerts: Toggle audio on/off
  • Log to CSV: Save posture data for analysis

Live Metrics:

  • Shoulder angle deviation
  • Neck angle deviation
  • Overall posture score

Session Statistics:

  • Time in good posture
  • Time in bad posture
  • Number of alerts triggered

πŸŽ“ Personalized Training (Recommended)

For best results, train a personalized model:

Why Use Training?

  • Adapts to YOUR body: Everyone sits differently
  • More accurate: Custom thresholds based on your posture
  • Better alerts: Fewer false positives
  • Learns continuously: Improves with feedback

How to Train

  1. Click "Start Training" in the control panel

  2. Capture Good Posture Samples (5-10 samples):

    • Sit in your ideal posture
    • Click "Capture Sample"
    • Move slightly between samples
    • Click "Next Step"
  3. Capture Bad Posture Samples (5-10 samples):

    • Slouch or lean forward (intentionally bad)
    • Click "Capture Sample"
    • Vary your bad posture slightly
    • Click "Next Step"
  4. Complete Training:

    • Click "Finish Training"
    • Your custom model is now active!

Training vs Quick Calibration

Feature Quick Calibration Personalized Training
Time 5 seconds 2-3 minutes
Samples 1 10-20
Accuracy Good Excellent
Learning No Yes (with feedback)
Best For Quick setup Daily use

Recommendation: Use Quick Calibration for immediate setup, then train a Personalized Model for best accuracy.

πŸ”§ Configuration

You can adjust sensitivity in posture.js:

// Alert timing (lines 18-19)
this.alertDelay = 3000;      // Wait 3 seconds before alert
this.alertCooldown = 5000;   // 5 seconds between alerts

// Posture thresholds (lines 12-14)
this.shoulderAngleThreshold = 15;  // degrees
this.neckAngleThreshold = 10;      // degrees
this.deviationThreshold = 12;      // overall deviation

πŸ“ Project Structure

poster_monitor_2/
β”œβ”€β”€ main.js              # Electron main process
β”œβ”€β”€ renderer.js          # Webcam & AI inference
β”œβ”€β”€ posture.js           # Posture analysis & alerts
β”œβ”€β”€ training.js          # Personalized training system
β”œβ”€β”€ index.html           # UI layout
β”œβ”€β”€ styles.css           # Modern UI styles
β”œβ”€β”€ beep.mp3             # Alert sound
β”œβ”€β”€ assets/              # Visual guides
β”‚   β”œβ”€β”€ good-posture.svg
β”‚   β”œβ”€β”€ bad-posture.svg
β”‚   └── posture-comparison.svg
β”œβ”€β”€ package.json         # Dependencies
└── README.md            # This file

πŸ› Troubleshooting

Camera Not Working

  • macOS: System Preferences β†’ Security & Privacy β†’ Camera β†’ Enable for Electron
  • Windows: Settings β†’ Privacy β†’ Camera β†’ Allow apps to access camera
  • Restart the app after granting permissions

Model Loading Failed

  • Ensure internet connection on first run only
  • Check console for errors: View β†’ Toggle Developer Tools β†’ Console
  • Delete node_modules and run npm install again

Calibration Failed

  • Ensure you're fully visible in the camera frame
  • Improve lighting (face a window or turn on lights)
  • Make sure head, shoulders, and hips are visible
  • Try moving closer/farther from camera

No Pose Detected

  • Check lighting conditions
  • Ensure upper body is in frame
  • Remove clutter from background
  • Try different camera angles

Audio Not Playing

  • Check system volume
  • Verify beep.mp3 exists in project directory
  • Test audio file separately
  • Check DevTools console for errors

πŸ” Privacy & Security

  • No internet required after initial setup
  • No data collection or analytics
  • No external API calls
  • All processing happens locally on your device
  • Webcam feed never leaves your computer
  • Training data stored locally in ~/Library/Application Support/PostureMonitor/

Your data never leaves your Mac!

πŸ’» Development

Run with Developer Tools

npm run dev

Dependencies

  • electron: Desktop app framework
  • @tensorflow-models/pose-detection: AI pose estimation
  • @tensorflow/tfjs-core: TensorFlow.js core
  • @tensorflow/tfjs-backend-webgl: GPU acceleration
  • @tensorflow/tfjs-converter: Model converter

Building for Distribution

npm install --save-dev electron-builder
npm run build

🎯 Tips for Best Results

  1. Lighting: Ensure good, even lighting
  2. Camera Position: Eye level, 2-3 feet away
  3. Background: Clear, uncluttered background
  4. Consistency: Use the same setup daily
  5. Recalibrate: If you change desk/chair height
  6. Take Breaks: Stand up and stretch every 30 minutes!

πŸ“Š Optional CSV Logging

Enable "Log to CSV" to save posture data:

  • Logs every frame with timestamp
  • Exports to posture_log_YYYY-MM-DD_HH-MM-SS.csv
  • Useful for tracking progress over time

CSV Format:

timestamp,status,shoulderAngle,neckAngle,spineAngle,overallDeviation
2025-10-13T10:30:00.000Z,good,2.34,3.45,1.23,2.50

⚑ Performance

  • CPU Usage: ~15-25% on modern MacBooks
  • Memory: ~200-400MB
  • GPU: Uses Metal (via WebGL) for acceleration
  • Speed: 30-60 FPS real-time detection

πŸ“ License

MIT License - Feel free to modify and distribute

πŸ™ Acknowledgments

πŸŽ‰ Enjoy Better Posture!

Remember: This app is a tool to build awareness. Take regular breaks, stretch, and consult a healthcare professional for persistent posture issues.


Made with ❀️ for better ergonomics and health

Need Help?

  1. Check the Troubleshooting section above
  2. Open DevTools (View β†’ Toggle Developer Tools) to see console logs
  3. Ensure all dependencies are installed: npm install
  4. Make sure your webcam is working in other apps first

Contributing

Found a bug or have a feature idea? Feel free to open an issue or submit a pull request!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors