Skip to content

DapCodes/Pose-Recognition-Exercise-Counter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Gym Counter

Real-time Exercise Counting System with Computer Vision

Python MediaPipe OpenCV License


Overview

AI Gym Counter is a desktop application that leverages computer vision and AI-powered pose estimation to automatically detect, track, and count exercise repetitions in real-time. The system processes live video feed from a webcam using advanced pose landmark detection and geometric analysis to provide immediate feedback on exercise form and repetition counting across multiple exercise types.

Core Computer Vision Features

  • Real-time Pose Estimation: Processes 33 body skeleton landmarks at 30fps using MediaPipe Pose framework
  • Joint Angle Calculation: Computes 3D angles between joint triplets (shoulder-elbow-wrist, hip-knee-ankle) using vector geometry
  • Motion State Detection: Classifies exercise phases (down/up) through continuous angle threshold crossing analysis
  • Form Validation: Monitors secondary angle constraints to detect and alert improper exercise form in real-time
  • Skeleton Visualization: Renders annotated skeletal overlay with color-coded feedback (green for correct form, blue for attention needed)

Key Features

  • 5 Exercise Modes: Push-Up, Squat, Bicep Curl, Shoulder Press, Sit-Up
  • Adaptive Difficulty Levels: Beginner, Intermediate, Advanced with calibrated angle thresholds
  • Live Form Feedback: Real-time posture correction cues with visual and audio indicators
  • Session Tracking: Complete workout statistics including repetition count, estimated calories, accuracy metrics, and duration
  • Workout History: Persistent SQLite database storing all session records with exercise metadata
  • Analytics Dashboard: Weekly repetition charts and exercise distribution analytics
  • Multi-threaded Architecture: Non-blocking camera processing thread ensuring responsive UI performance

Installation

Prerequisites

  • Python 3.9 or higher
  • Webcam (integrated or external)
  • 2GB RAM minimum

Quick Start

# Clone the repository
git clone https://github.com/yourusername/ai-gym-counter
cd ai-gym-counter

# Install dependencies
pip install -r requirements.txt

# Launch the application
python main.py

Project Architecture

ai_gym_counter/
├── main.py                       # Application entry point and UI framework
├── requirements.txt              # Python dependencies
├── models/
│   └── pose_detector.py          # Computer vision module with MediaPipe wrapper
├── exercises/
│   └── exercise_models.py        # Exercise-specific rep counting logic and angle thresholds
├── utils/
│   ├── camera_thread.py          # Asynchronous video stream processing
│   └── sound_manager.py          # Audio feedback controller
├── database/
│   └── db_manager.py             # Session persistence and analytics queries
└── assets/
    ├── pose_landmarker.task      # MediaPipe pose detection model
    └── workout_history.db        # Auto-generated session database

Technical Implementation

Computer Vision Pipeline

The system operates through a four-stage computer vision and motion analysis pipeline:

  1. Frame Capture & Preprocessing: OpenCV acquires video frames from the webcam input stream
  2. Pose Detection: MediaPipe Pose processes RGB frames and detects 33 body landmarks with confidence scores
  3. Angle Computation: Three-point geometric calculations derive joint angles from landmark coordinates
  4. Motion Classification: Continuous angle monitoring detects state transitions (DOWN to UP) to increment repetition counter

Exercise-Specific Angle Thresholds

Exercise Down State Up State Primary Joints Validation
Push-Up < 90° > 160° Shoulder-Elbow-Wrist Torso alignment
Squat < 95° > 165° Hip-Knee-Ankle Knee tracking
Bicep Curl > 160° < 40° Shoulder-Elbow-Wrist Elbow stability
Shoulder Press < 90° > 165° Shoulder-Elbow-Wrist Shoulder stability
Sit-Up > 160° < 70° Shoulder-Hip-Knee Spine alignment

Form Detection Algorithm

The form validation system continuously monitors secondary angle constraints and geometric relationships to detect deviation from proper exercise form. Visual feedback is provided through:

  • Green skeleton overlay: Correct form detected
  • Blue skeleton overlay: Form correction recommended
  • Alert indicators: Secondary constraint violations

Technology Stack

Component Technology
Core Language Python 3.9+
Computer Vision OpenCV 4.8+, MediaPipe Pose (TensorFlow Lite)
User Interface Tkinter, PIL
Data Persistence SQLite3
Analytics Matplotlib
Audio Pygame mixer
Threading Python multiprocessing

UI Design

The interface employs a modern, dark-themed design optimized for extended use:

  • Color Scheme: Deep background (#0c0c0c), accent blue (#7eb8d4), status green (#4ade80)
  • Components: Animated progress indicators, real-time stat cards, segmented exercise selector
  • Layout: Responsive grid with camera feed dominant, statistics sidebar
  • Feedback: Immediate visual and audio cues for rep completion and form corrections

Use Cases

  • Personal fitness training at home with real-time form feedback
  • Physical rehabilitation monitoring with form adherence verification
  • Workout logging and performance tracking over time
  • AI-assisted personal training without requiring specialized hardware

Performance Specifications

  • Frame Processing: 30fps real-time performance on standard laptops
  • Pose Detection Latency: <100ms per frame
  • Memory Usage: 200-300MB during operation
  • GPU Support: Optional CUDA acceleration for compatible NVIDIA devices

Requirements

Full dependency list available in requirements.txt:

opencv-python>=4.8.0
mediapipe==0.10.13
numpy>=1.24.0
Pillow>=10.0.0
matplotlib>=3.7.0
pygame>=2.5.0
customtkinter>=5.2.0

Future Enhancements

  • Real-time video recording with form annotations
  • Advanced skeleton analysis for injury prevention
  • Comparative form analysis across multiple sessions
  • Mobile application deployment (Flutter/React Native)
  • Cloud-based analytics and social sharing

License

MIT License - See LICENSE file for details

Author

Developed as a portfolio project demonstrating computer vision integration with Python desktop applications. | Image | Pillow |

Screenshots

Run the app and connect your webcam to see the dashboard in action.

License

MIT — free for personal and commercial use.

About

Real-time exercise repetition counter using computer vision and pose estimation. Detects and counts reps for 5 exercises with form validation and session analytics. Powered by MediaPipe and OpenCV.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages