Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

🏋️ FitFlex - AI Workout Trainer

AI-powered workout trainer with face recognition and bicep curl rep counting using MediaPipe and OpenCV.

Python Flask MediaPipe

✨ Features

  • 👤 Face Recognition Login - Secure user authentication using facial recognition
  • 💪 Bicep Curl Counter - Real-time rep counting for both arms independently
  • 📊 Live Statistics - Track right arm, left arm, and total reps
  • 🎥 Live Video Feed - Real-time pose detection with skeleton overlay
  • 🔄 Reset Functionality - Easy counter reset between sets
  • 🎯 Angle Detection - Real-time elbow angle measurement
  • Smoothing Algorithm - Noise reduction for accurate counting

🛠️ Technologies Used

  • Python 3.11 - Backend programming
  • Flask - Web framework for API
  • Flask-CORS - Cross-origin resource sharing
  • MediaPipe - Pose detection and face mesh recognition
  • OpenCV - Computer vision and video processing
  • NumPy - Numerical computations
  • Pickle - User data storage

📋 Installation

Prerequisites

  • Python 3.11 or higher
  • Webcam
  • Windows/Mac/Linux

Setup

  1. Clone the repository:
git clone https://github.com/Kush2605/FitFlex-AI-Workout-Trainer.git
cd FitFlex-AI-Workout-Trainer
  1. Create virtual environment:
python -m venv cv_env
  1. Activate virtual environment:

Windows:

cv_env\Scripts\activate

Mac/Linux:

source cv_env/bin/activate
  1. Install dependencies:
pip install -r requirements.txt

🚀 How to Run

Backend Server

python app.py

Server will start at http://localhost:5000

Standalone Rep Counter (OpenCV Window)

python pose_test.py

📡 API Endpoints

Endpoint Method Description
/ GET Health check
/signup POST Register new user with face
/signin POST Login with face recognition
/signout POST Logout current user
/video_feed GET Live video stream
/get_counts GET Get current rep counts
/reset GET Reset rep counters
/get_current_user GET Get logged-in user

📁 Project Structure

FitFlex-AI-Workout-Trainer/
│
├── app.py                    # Flask backend with API
├── pose_test.py              # Standalone rep counter
├── camera_test.py            # Camera test utility
├── requirements.txt          # Python dependencies
├── .gitignore               # Git ignore rules
├── README.md                # Documentation
└── mediapipe_users.pkl      # User face data (auto-generated)

🎯 How It Works

Face Recognition

  1. Captures 10 frames of user's face using MediaPipe FaceMesh
  2. Extracts 468 facial landmarks per frame
  3. Normalizes and stores facial embeddings
  4. Compares new faces with stored embeddings for login

Rep Counting

  1. Detects body pose using MediaPipe Pose (33 landmarks)
  2. Calculates elbow angle using shoulder, elbow, and wrist coordinates
  3. Applies 5-frame moving average for smoothing
  4. Detects "up" position (angle > 165°) and "down" position (angle < 65°)
  5. Requires 5 consecutive frames to confirm rep completion
  6. Tracks left and right arms independently

🧮 Angle Calculation

def calculate_angle(a, b, c):
    # Vector from b to c (elbow to wrist)
    # Vector from b to a (elbow to shoulder)
    radians = arctan2(c.y - b.y, c.x - b.x) - arctan2(a.y - b.y, a.x - b.x)
    angle = abs(radians * 180 / π)
    return 360 - angle if angle > 180 else angle

🔧 Configuration

  • CONFIRM_FRAMES = 5 (frames needed to confirm rep)
  • Angle threshold (up) = 165°
  • Angle threshold (down) = 65°
  • Smoothing window = 5 frames
  • Face recognition threshold = 0.6

🎨 Frontend Integration

To integrate with a web frontend:

  1. Update BACKEND_URL in your HTML/JS
  2. Use fetch() to call API endpoints
  3. Display video feed using <img> tag with /video_feed endpoint
  4. Poll /get_counts every 200ms for real-time updates

Example:

const BACKEND_URL = 'http://localhost:5000';

// Start workout
document.getElementById('video').src = `${BACKEND_URL}/video_feed`;

// Get counts
setInterval(async () => {
    const response = await fetch(`${BACKEND_URL}/get_counts`);
    const data = await response.json();
    console.log(data.total); // Total reps
}, 200);

🐛 Troubleshooting

Camera not opening:

  • Check if webcam is connected
  • Grant camera permissions
  • Close other apps using camera

Face not recognized:

  • Ensure good lighting
  • Face the camera directly
  • Sign up again if needed

Reps not counting:

  • Check arm is fully extended (165°)
  • Check full curl (65°)
  • Ensure pose detection working (skeleton visible)

📝 Future Enhancements

  • Add more exercises (squats, push-ups, etc.)
  • Workout history tracking
  • Form correction feedback
  • Mobile app
  • Cloud deployment
  • Multiple user profiles
  • Exercise recommendations

Made with ❤️ and 💪 by Kush Bansal

About

AI-powered workout trainer with face recognition and rep counting

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages