Skip to content

alphoder/Exercise-Predictor-and-Posture-corrector

Repository files navigation

Exercise Predictor & Posture Corrector

A real-time exercise posture correction app that uses your webcam to detect exercises, count reps, and speak corrections aloud to help you maintain proper form.

Features

  • Exercise Detection — Automatically identifies squats, push-ups, and planks from your webcam feed
  • Rep Counting — Tracks repetitions with a state machine (and hold time for planks)
  • Posture Analysis — 11 rule-based checks across 3 exercises using joint angle calculations
  • Voice Feedback — Speaks corrections through your browser speakers with smart throttling (no repeated nagging)
  • Visual Overlay — Color-coded skeleton (green/orange/red) with feedback text on the video feed
  • EMA Smoothing — Reduces landmark jitter for stable angle readings

Supported Exercises & Posture Rules

Exercise Rules Checked
Squat Back straightness, knee valgus (caving in), squat depth, knees over toes
Push-up Body alignment (sag/pike), elbow flare, range of motion, head position
Plank Hip position (sag/pike), head alignment, elbow placement under shoulders

Tech Stack

  • MediaPipe — Pose estimation (33 body landmarks)
  • Streamlit — Web UI
  • streamlit-webrtc — Real-time webcam streaming
  • OpenCV — Frame processing and visual overlay
  • Web Speech API — Browser-native text-to-speech for voice feedback

Setup

Prerequisites

  • Python 3.10+
  • Webcam
  • A browser that supports Web Speech API (Chrome, Edge, Safari)

Installation

git clone https://github.com/alphoder/Exercise-Predictor-and-Posture-corrector.git
cd Exercise-Predictor-and-Posture-corrector
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Run

streamlit run app.py

The app opens in your browser. Click START, allow camera access, and begin exercising.

Usage Tips

  • Position your camera from the side for best results with all three exercises
  • Ensure your full body is visible in the frame
  • Good lighting improves pose detection accuracy
  • Use the sidebar to toggle voice feedback on/off or reset the rep counter

Project Structure

├── app.py                    # Streamlit UI, WebRTC streaming, main pipeline
├── pose_estimator.py         # MediaPipe PoseLandmarker wrapper + visual overlay
├── exercise_classifier.py    # Exercise detection + rep counting state machine
├── posture_analyzer.py       # Per-exercise posture correction rules
├── voice_feedback.py         # Throttled TTS via Web Speech API
├── angle_utils.py            # Joint angle geometry calculations
├── config.py                 # All thresholds and constants
└── requirements.txt          # Dependencies

How It Works

Each webcam frame flows through this pipeline (~20-35ms per frame):

Webcam Frame
  → MediaPipe Pose (33 landmarks)
    → Exercise Classifier (orientation + angle patterns → exercise type + rep state)
      → Posture Analyzer (joint angle rules → feedback list)
        → Visual Overlay (colored skeleton + text)
        → Voice Queue (throttled, priority-sorted browser TTS)

License

MIT

About

Real-time exercise posture correction using MediaPipe pose estimation. Detects squats, push-ups & planks with voice feedback.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages