AI-powered workout trainer with face recognition and bicep curl rep counting using MediaPipe and OpenCV.
- 👤 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
- 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
- Python 3.11 or higher
- Webcam
- Windows/Mac/Linux
- Clone the repository:
git clone https://github.com/Kush2605/FitFlex-AI-Workout-Trainer.git
cd FitFlex-AI-Workout-Trainer- Create virtual environment:
python -m venv cv_env- Activate virtual environment:
Windows:
cv_env\Scripts\activateMac/Linux:
source cv_env/bin/activate- Install dependencies:
pip install -r requirements.txtpython app.pyServer will start at http://localhost:5000
python pose_test.py| 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 |
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)
- Captures 10 frames of user's face using MediaPipe FaceMesh
- Extracts 468 facial landmarks per frame
- Normalizes and stores facial embeddings
- Compares new faces with stored embeddings for login
- Detects body pose using MediaPipe Pose (33 landmarks)
- Calculates elbow angle using shoulder, elbow, and wrist coordinates
- Applies 5-frame moving average for smoothing
- Detects "up" position (angle > 165°) and "down" position (angle < 65°)
- Requires 5 consecutive frames to confirm rep completion
- Tracks left and right arms independently
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- 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
To integrate with a web frontend:
- Update
BACKEND_URLin your HTML/JS - Use
fetch()to call API endpoints - Display video feed using
<img>tag with/video_feedendpoint - Poll
/get_countsevery 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);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)
- 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