Skip to content

sumit1kr/FitVision-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advanced Exercise Tracker (OpenCV + MediaPipe + Voice)

An AI-powered, real-time exercise form tracker that uses your webcam to detect body pose, count reps, check form quality, visualize progress & symmetry, give voice coaching, and save your workout as a CSV log. Supports Bicep Curls, Squats, Push-ups, and Lunges.


✨ Features

  • Real-time Pose Tracking with MediaPipe Pose (33 landmarks).
  • Rep Counting with robust stage detection to avoid double counts.
  • Form Feedback (on-screen + voice coaching) with color-coded messages.
  • Progress Bar (rep completion) and Symmetry Gauge (left/right balance).
  • Auto Set & Rest Timer: every 10 reps → start a 60s rest.
  • Tutorial Mode: press h to hear how to perform the current exercise.
  • Data Logging: press s to append a detailed row to workout_data.csv.
  • Fullscreen Toggle: press f to focus on movement.
  • Keyboard Controls to switch exercises instantly.

🧠 Why this project?

Most rep counters only detect movement; they don’t care about form. This tracker measures joint angles, detects symmetry between left and right sides, gives actionable tips, and even talks to you so you can keep your eyes off the screen.


🖥️ Tech Stack

  • Python
  • OpenCV for video capture and on-screen UI overlays
  • MediaPipe Pose for landmark detection
  • NumPy for angle math
  • pyttsx3 for offline Text‑to‑Speech (voice guidance)

📦 Installation

Python: 3.9–3.12 recommended

# 1) Create & activate a virtual environment (recommended)
python -m venv .venv
# Windows
.venv\Scripts\activate
# macOS/Linux
source .venv/bin/activate

# 2) Install dependencies
pip install -r requirements.txt

If MediaPipe fails to build on Linux, ensure you have recent pip, setuptools, and system build tools installed.


▶️ Run

python main.py

The app starts fullscreen. You can toggle fullscreen with f.

Key controls

  • 1 Bicep Curl
  • 2 Squat
  • 3 Push-up
  • 4 Lunge
  • h Voice tutorial for the current exercise
  • s Save current session snapshot to workout_data.csv
  • f Toggle fullscreen
  • q Quit

🧩 How it works (high level)

  1. OpenCV grabs frames from the webcam and draws UI overlays.
  2. MediaPipe Pose finds body landmarks each frame.
  3. For the selected exercise, the tracker computes specific joint angles and updates:
    • Stage (e.g., “up”/“down”)
    • Rep counters and per‑rep timing
    • Form feedback, progress, and symmetry
  4. When form feedback changes (and after a cooldown), pyttsx3 speaks it out without blocking the video loop.
  5. Press s to append a row to workout_data.csv (timestamp, reps/sets, session duration).

🤖 Voice Coaching

  • Uses pyttsx3 for local/offline Text‑to‑Speech.
  • Runs speaking in a background thread to avoid UI freezes.
  • Speaks only when feedback changes and obeys a small cooldown to prevent spam.
  • h will speak the tutorial for the current exercise any time.

🏋️‍♀️ Exercise detection details

Below are the core ideas. Thresholds can be tuned per user.

1) Bicep Curl

  • Landmarks: shoulder → elbow → wrist
  • Angle: elbow angle
  • Rep logic: when the arm is extended (angle > 160°) → stage = down; when fully curled (angle < 30°) from downcount 1 rep.
  • Extras:
    • Tracks left & right arms separately with screen‑aware orientation.
    • Symmetry score = 100 − (|left−right elbow angle| × factor).
    • Progress bar fills as the elbow approaches full curl.

2) Squat

  • Landmarks: hip → knee → ankle (both legs)
  • Angles: left & right knee angles; uses average
  • Rep logic: average angle > 160° → stage = up; average angle < 90° from upcount 1 rep.
  • Form tips: warns if knees are not aligned (big L/R angle mismatch).

3) Push‑up

  • Landmarks: shoulder → elbow → wrist (both arms) + back line
  • Angles: left & right elbow angles; uses average
  • Rep logic: average angle > 160° → stage = up; average angle < 90° from upcount 1 rep.
  • Form tips:
    • Checks back straightness using shoulder‑hip‑ankle angle ≈ 180° (tolerance ~15°).
    • Gives “go deeper” or “good depth” feedback.

4) Lunge

  • Landmarks: hips, knees, ankles (both sides) + shoulders
  • Angles: both knee angles and both hip angles
  • Forward leg detection: the leg with smaller hip angle is considered forward.
  • Rep logic: forward knee < 90° from up and back leg > 160° → count 1 rep.
  • Form tips: asks to straighten back leg, align knees with ankle, or step deeper.

📊 On‑screen UI

  • Top‑left panel: exercise name, reps (both arms for curls), set #, stage, workout timer, rest countdown when active.
  • Progress bar: bottom‑left (0–100% of the current rep).
  • Symmetry gauge: top‑right circular meter (0–100).
  • Color‑coded feedback:
    • 🟩 Green — good form cues
    • 🟧 Orange — caution (improve depth/range)
    • 🟥 Red — form issues (e.g., knees misaligned / back not straight)

🗃️ Data logging (workout_data.csv)

  • Columns: Timestamp, Exercise, Left Reps, Right Reps, Total Reps, Sets, Workout Duration.
  • For Bicep Curls, left/right reps are recorded independently; for other exercises, those columns are “-”.
  • A simple --- divider row separates sessions.

Tip: You can import the CSV into a spreadsheet to visualize progress.


⚙️ Configuration

  • Set size: 10 reps (auto rest after reaching 10).
  • Rest duration: 60s.
  • Voice rate: adjustable in main.py.
  • Angle thresholds: inside exercise_tracker.py (per‑exercise).

📁 Project structure

.
├── main.py                # App entry: webcam loop, drawing, keyboard, voice
├── exercise_tracker.py    # Exercise logic: counters, stages, feedback, saving
├── pose_utils.py          # Math helpers: angles, landmark fetch, UI widgets
├── workout_data.csv       # Created at runtime when you press 's'
├── requirements.txt
└── README.md

🧰 Troubleshooting

  • No camera found: ensure another app isn’t using the webcam; try a different index in cv2.VideoCapture(0).
  • No voice output: check system volume; on Linux, install a TTS backend (e.g., espeak).
  • Low FPS: reduce camera resolution or close other apps. Lighting significantly affects pose stability.
  • Mediapipe install issues: upgrade pip/setuptools, or try a different Python version (3.10–3.11 work well).

🗺️ Roadmap ideas

  • Per‑user calibration of angle thresholds
  • More exercises (plank, shoulder press, deadlift with safety checks)
  • Workout history dashboard & charts
  • Rep speed / tempo analysis and coaching
  • Optional cloud sync

🙌 Acknowledgments

  • MediaPipe team for high‑quality pose estimation
  • OpenCV community
  • pyttsx3 contributors for simple offline TTS

📜 License

MIT — feel free to use and adapt. Consider opening PRs for improvements!

About

AI-powered fitness coach using OpenCV + MediaPipe for real-time pose tracking, rep counting, form correction, and voice guidance. Supports Bicep Curls, Squats, Push-ups, and Lunges with progress visualization, set tracking, rest timers, and workout logging.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages