Skip to content

yakupzengin/fitness-trainer-pose-estimation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

59 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ‹οΈ Fitness Trainer with AI Pose Estimation

An AI-powered web application that tracks your exercises using computer vision and provides real-time form feedback with scoring.

Python Flask MediaPipe License


✨ Features

πŸŽ₯ Real-time Exercise Tracking

  • πŸ“· Real-time Pose Estimation using MediaPipe
  • 🎯 18 Built-in Exercises - Full body workout coverage
  • πŸ“Š Form Score System (0-100) with A-F grading
  • πŸ”„ Automatic Rep Counting with state machine logic
  • πŸ’¬ Real-time Form Feedback - Instant correction tips

πŸ“Ή Video Analysis Mode

  • 🎬 Upload & Analyze Videos - Process pre-recorded workout videos
  • 🦴 Skeleton Overlay - See your pose detection on processed video
  • πŸ“ˆ Live Statistics Panel - Real-time rep count, form score, and state
  • πŸ–₯️ Processing Terminal - Watch analysis progress with detailed logs
  • πŸ’Ύ H.264 Video Output - Browser-compatible processed videos with imageio-ffmpeg

πŸ‘€ User Profile System

  • πŸ“‹ Personal Information - Track your fitness journey
  • 🎯 Customizable Goals - Set weekly workout and rep targets
  • πŸ… Achievement System - Unlock badges for milestones
  • πŸ“Š Activity Charts - Visualize your workout history
  • ❀️ Favorite Exercises - Track your most-used exercises
  • βš™οΈ Settings - Dark mode, notifications, units preference

πŸ“Š Dashboard

  • πŸ“ˆ Workout Statistics - Total workouts, reps, streaks
  • πŸ“‰ Weekly Activity Charts - Visualize your progress
  • πŸ₯§ Exercise Distribution - See which exercises you do most
  • πŸ“‹ Recent Workouts - Quick view of latest sessions

βš™οΈ Extensible Architecture

  • πŸ“ YAML-based Exercise Definitions - Add new exercises without writing code!
  • πŸ”€ Three Exercise Types - Standard, Bilateral (left/right), Duration-based
  • 🎨 Customizable Visualization - Colors, highlighted joints per exercise

πŸ—οΈ System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        FRONTEND (Web UI)                             β”‚
β”‚         index.html ← video stream (MJPEG) ← form feedback            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚ HTTP/WebSocket
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         BACKEND (Flask)                              β”‚
β”‚                            app.py                                    β”‚
β”‚   β€’ Video capture & streaming                                        β”‚
β”‚   β€’ REST API endpoints                                               β”‚
β”‚   β€’ Session management                                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      EXERCISE ENGINE                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚
β”‚  β”‚  BaseExercise  β”‚  β”‚    Loader      β”‚  β”‚     Engine     β”‚         β”‚
│  │   (FSM Core)   │  │  (YAML→Obj)    │  │   (Wrapper)    │         │
β”‚  β”‚                β”‚  β”‚                β”‚  β”‚                β”‚         β”‚
β”‚  β”‚ β€’ State Machineβ”‚  β”‚ β€’ Parse YAML   β”‚  β”‚ β€’ process_frameβ”‚         β”‚
β”‚  β”‚ β€’ Rep Counter  β”‚  β”‚ β€’ Validate     β”‚  β”‚ β€’ draw_overlay β”‚         β”‚
β”‚  β”‚ β€’ Form Score   β”‚  β”‚ β€’ Create Obj   β”‚  β”‚ β€’ draw_score   β”‚         β”‚
β”‚  β”‚ β€’ Feedback     β”‚  β”‚                β”‚  β”‚                β”‚         β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚
β”‚         β–²                                                            β”‚
β”‚         β”‚ inheritance                                                β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                               β”‚
β”‚  β”‚  Bilateral   β”‚  β”‚   Duration     β”‚                               β”‚
β”‚  β”‚  Exercise    β”‚  β”‚   Exercise     β”‚                               β”‚
β”‚  β”‚ (L/R sides)  β”‚  β”‚ (time-based)   β”‚                               β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚ loads
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    YAML DEFINITIONS (18 exercises)                   β”‚
β”‚  squat.yaml β”‚ push_up.yaml β”‚ plank.yaml β”‚ deadlift.yaml β”‚ ...       β”‚
β”‚                                                                      β”‚
β”‚  Each YAML contains:                                                 β”‚
β”‚  β€’ Angle definitions (landmarks, ranges)                             β”‚
β”‚  β€’ State machine (states, transitions, conditions)                   β”‚
β”‚  β€’ Counter rules (when to count a rep)                               β”‚
β”‚  β€’ Form feedback rules (warnings, priorities)                        β”‚
β”‚  β€’ Tempo guidance (up/down/hold timing)                              β”‚
β”‚  β€’ Visualization config (colors, highlighted joints)                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“Š Form Score System

The app calculates a Form Score (0-100) for each exercise session:

Component Weight Description
Angle Accuracy 40% How close your angles are to ideal
Tempo Compliance 30% Following the recommended speed
Form Feedback 30% Penalty for triggered warnings

Grade Scale

Score Grade Color
90-100 A 🟒 Green
80-89 B πŸ”΅ Blue
70-79 C 🟑 Yellow
60-69 D 🟠 Orange
0-59 F πŸ”΄ Red

πŸ“ Available Exercises (18)

Upper Body

  • πŸ’ͺ Hammer Curl - Bicep curl with neutral grip
  • πŸ’ͺ Bicep Curl - Classic bicep exercise (bilateral)
  • πŸ’ͺ Tricep Dip - Chair/bench dips for triceps
  • πŸ’ͺ Shoulder Press - Overhead pressing
  • πŸ’ͺ Lateral Raise - Side delt raises
  • πŸ’ͺ Push Up - Classic chest exercise

Lower Body

  • 🦡 Squat - Bodyweight squat
  • 🦡 Lunge - Forward lunge (bilateral)
  • 🦡 Side Lunge - Lateral lunge
  • 🦡 Deadlift - Romanian deadlift for hamstrings
  • 🦡 Glute Bridge - Hip bridge for glutes
  • 🦡 Calf Raise - Standing calf raises
  • 🦡 Wall Sit - Isometric hold (duration)

Cardio / Full Body

  • πŸ”₯ Mountain Climber - Dynamic core/cardio
  • πŸ”₯ High Knees - Running in place
  • πŸ”₯ Jumping Jack - Classic cardio move
  • πŸ”₯ Leg Raise - Lying leg raises for abs
  • 🧘 Plank - Core hold (duration)

πŸš€ Quick Start

1. Clone & Install

git clone https://github.com/yourusername/fitness-trainer-pose-estimation.git
cd fitness-trainer-pose-estimation

# Create virtual environment (optional)
python -m venv venv
source venv/bin/activate  # Linux/Mac
# or: venv\Scripts\activate  # Windows

# Install dependencies
pip install -r requirements.txt

2. Run the Application

python app.py

3. Open in Browser

Navigate to: http://127.0.0.1:5000


βž• Adding New Exercises

No coding required! Just create a YAML file:

Step 1: Create YAML in exercises/definitions/

# exercises/definitions/my_new_exercise.yaml
name: "My New Exercise"
type: "standard"  # or "bilateral" / "duration"
description: "Description of the exercise"

# Define body angles to track
angles:
  primary_angle:
    landmarks: [11, 13, 15]  # MediaPipe landmark IDs
    range: [30, 170]         # Valid angle range

# State machine definition
states:
  - name: "START"
    condition:
      angle: "primary_angle"
      operator: ">"
      value: 150
    next_state: "MIDDLE"
    feedback: "Starting position"
    
  - name: "MIDDLE"
    condition:
      angle: "primary_angle"
      operator: "<"
      value: 60
    next_state: "END"
    feedback: "Good form!"
    
  - name: "END"
    condition:
      angle: "primary_angle"
      operator: ">"
      value: 150
    next_state: "START"
    feedback: "Rep complete!"

# When to count a rep
counter:
  increment_on: "END"

# Form warnings
feedback:
  - name: "form_warning"
    description: "Bad form detected"
    angle: "primary_angle"
    condition:
      operator: "<"
      value: 30
    message: "Don't go too low!"
    priority: 1

# Tempo in seconds
tempo:
  up_seconds: 1.0
  down_seconds: 2.0
  hold_seconds: 0.5

# Display settings
visualization:
  primary_angle: "primary_angle"
  show_angles: ["primary_angle"]
  highlight_landmarks: [11, 13, 15]
  color_scheme: "green"

Step 2: Test

python test_engine.py

Step 3: Use

Restart the app - your exercise is now available!


πŸ“ MediaPipe Landmarks Reference

 0  = NOSE                    
11  = LEFT_SHOULDER       12 = RIGHT_SHOULDER
13  = LEFT_ELBOW          14 = RIGHT_ELBOW
15  = LEFT_WRIST          16 = RIGHT_WRIST
23  = LEFT_HIP            24 = RIGHT_HIP
25  = LEFT_KNEE           26 = RIGHT_KNEE
27  = LEFT_ANKLE          28 = RIGHT_ANKLE
31  = LEFT_FOOT_INDEX     32 = RIGHT_FOOT_INDEX

πŸ“‚ Project Structure

fitness-trainer-pose-estimation/
β”œβ”€β”€ πŸ“„ app.py                    # Flask application + video streaming
β”œβ”€β”€ πŸ“„ video_processor.py        # Standalone video analysis with skeleton overlay
β”œβ”€β”€ πŸ“„ main.py                   # CLI runner (standalone)
β”œβ”€β”€ πŸ“„ requirements.txt
β”‚
β”œβ”€β”€ πŸ“ exercises/
β”‚   β”œβ”€β”€ πŸ“„ base_exercise.py      # FSM engine (BaseExercise, Bilateral, Duration)
β”‚   β”œβ”€β”€ πŸ“„ loader.py             # YAML loader & validator
β”‚   β”œβ”€β”€ πŸ“„ engine.py             # High-level API wrapper
β”‚   └── πŸ“ definitions/          # 🎯 YAML exercise files (18 exercises)
β”‚       β”œβ”€β”€ squat.yaml
β”‚       β”œβ”€β”€ push_up.yaml
β”‚       β”œβ”€β”€ hammer_curl.yaml
β”‚       β”œβ”€β”€ bicep_curl.yaml
β”‚       β”œβ”€β”€ tricep_dip.yaml
β”‚       β”œβ”€β”€ shoulder_press.yaml
β”‚       β”œβ”€β”€ lateral_raise.yaml
β”‚       β”œβ”€β”€ lunge.yaml
β”‚       β”œβ”€β”€ side_lunge.yaml
β”‚       β”œβ”€β”€ deadlift.yaml
β”‚       β”œβ”€β”€ glute_bridge.yaml
β”‚       β”œβ”€β”€ calf_raise.yaml
β”‚       β”œβ”€β”€ wall_sit.yaml
β”‚       β”œβ”€β”€ plank.yaml
β”‚       β”œβ”€β”€ mountain_climber.yaml
β”‚       β”œβ”€β”€ high_knees.yaml
β”‚       β”œβ”€β”€ jumping_jack.yaml
β”‚       └── leg_raise.yaml
β”‚
β”œβ”€β”€ πŸ“ pose_estimation/
β”‚   β”œβ”€β”€ πŸ“„ estimation.py         # MediaPipe wrapper
β”‚   └── πŸ“„ angle_calculation.py  # Angle math
β”‚
β”œβ”€β”€ πŸ“ feedback/
β”‚   β”œβ”€β”€ πŸ“„ indicators.py         # UI components
β”‚   β”œβ”€β”€ πŸ“„ information.py        # Exercise metadata
β”‚   └── πŸ“„ layout.py
β”‚
β”œβ”€β”€ πŸ“ db/
β”‚   └── πŸ“„ workout_logger.py     # Workout history logging
β”‚
β”œβ”€β”€ πŸ“ templates/
β”‚   β”œβ”€β”€ πŸ“„ index.html            # Home - Real-time exercise tracking
β”‚   β”œβ”€β”€ πŸ“„ video_analysis.html   # Video upload & analysis page
β”‚   β”œβ”€β”€ πŸ“„ dashboard.html        # Stats dashboard
β”‚   └── πŸ“„ profile.html          # User profile & settings
β”‚
└── πŸ“ static/
    β”œβ”€β”€ πŸ“ css/
    β”‚   β”œβ”€β”€ πŸ“„ style.css         # Global styles
    β”‚   β”œβ”€β”€ πŸ“„ dashboard.css     # Dashboard page styles
    β”‚   β”œβ”€β”€ πŸ“„ profile.css       # Profile page styles
    β”‚   └── πŸ“„ video_analysis.css # Video analysis styles
    β”œβ”€β”€ πŸ“ js/
    β”‚   β”œβ”€β”€ πŸ“„ script.js         # Main page JavaScript
    β”‚   β”œβ”€β”€ πŸ“„ dashboard.js      # Dashboard functionality
    β”‚   β”œβ”€β”€ πŸ“„ profile.js        # Profile page functionality
    β”‚   └── πŸ“„ video_analysis.js # Video analysis functionality
    └── πŸ“ images/

πŸ”Œ API Endpoints

Endpoint Method Description
/ GET Home page - Real-time exercise tracking
/video_analysis GET Video upload & analysis page
/dashboard GET Workout statistics dashboard
/profile GET User profile & settings
/video_feed GET MJPEG video stream
/start_exercise POST Start tracking an exercise
/stop_exercise POST Stop current exercise
/get_status GET Get current rep count & form score
/exercises GET List all available exercises
/api/video/upload POST Upload video for analysis
/api/video/status/<id> GET Get video analysis status
/api/video/processed/<id> GET Download processed video
/api/profile/update POST Update user profile

πŸ–ΌοΈ Screenshots

Home - Real-time Tracking

Real-time pose estimation with skeleton overlay and form feedback.

Video Analysis

Upload videos, analyze with skeleton overlay, and download processed results.

Profile

Personal stats, achievements, goals tracking, and customizable settings.


πŸ› οΈ Technologies

  • Flask - Web framework
  • OpenCV - Computer vision & video processing
  • MediaPipe - Google's pose estimation model
  • imageio-ffmpeg - H.264 video encoding for browser compatibility
  • PyYAML - Exercise definition parsing
  • Chart.js - Interactive charts for dashboard
  • HTML/CSS/JS - Modern responsive frontend

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/new-exercise)
  3. Add your YAML exercise definition
  4. Run tests (python test_engine.py)
  5. Commit changes (git commit -am 'Add new exercise')
  6. Push to branch (git push origin feature/new-exercise)
  7. Create Pull Request

πŸ“œ License

MIT License - see LICENSE file for details.


πŸ™ Acknowledgments


Made with ❀️ for fitness enthusiasts

About

An AI-powered fitness tracker that uses real-time pose estimation to count reps, monitor form, and provide instant feedback for exercises like squats, push-ups, and bicep curls. Designed for accuracy, motivation, and adaptability

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors