Skip to content

A computer vision demo application that detects and counts dumbbell bicep curl repetitions using OpenCV and MediaPipe.

License

Notifications You must be signed in to change notification settings

alfa-echo-niner-ait/dumbbell_scoring

Repository files navigation

Dumbbell Lift Counter & Scorer

A computer vision demo application that detects and counts dumbbell bicep curl repetitions using OpenCV and MediaPipe. The system ensures proper form by requiring both arms to complete the movement simultaneously for a rep to count.

image

Features

  • Real-time Detection: Uses webcam feed to track arm movements with MediaPipe
  • Form Validation: Only counts reps when both arms move in sync (within the same frame)
  • Angle Calculation: Precise elbow joint angle measurement for accurate rep counting
  • Visual Feedback: Real-time display of rep count, score, and joint angles
  • Data Export: Automatically saves pose landmark data to CSV for analysis
  • Full-screen Interface: Clean, distraction-free workout monitoring

How It Works

Repetition Counting Logic

  • Movement Sequence: A rep is counted when both arms complete: "down" → "up" → "down"
  • Synchronization: Both arms must complete the movement within the same frame
  • Scoring: If only one arm completes the rep, no score is awarded
  • Angle Thresholds:
    • Down position: arm angle > 160°
    • Up position: arm angle < 50°

Angle Calculation Algorithm

The system calculates elbow joint angles using vector mathematics:

def calculate_angle(a, b, c):
    a, b, c = np.array(a), np.array(b), np.array(c)
    ba = a - b  # Vector from elbow to shoulder
    bc = c - b  # Vector from elbow to wrist
    cosine_angle = np.dot(ba, bc) / (np.linalg.norm(ba) * np.linalg.norm(bc))
    angle = np.arccos(np.clip(cosine_angle, -1.0, 1.0))
    return np.degrees(angle)

Mathematical Formula:

θ = arccos((BA · BC) / (||BA|| × ||BC||)) × (180/π)

Installation

Prerequisites

  • Python 3.7 or higher
  • Webcam
  • Windows/macOS/Linux

Step-by-Step Setup

  1. Clone the repository
git clone https://github.com/alfa-echo-niner-ait/dumbbell_scoring.git
cd dumbbell_scoring
  1. Create virtual environment
# On Windows
python -m venv venv
venv\Scripts\activate

# On macOS/Linux
python3 -m venv venv
source venv/bin/activate
  1. Install dependencies
pip install -r requirements.txt
  1. Run the application
python run.py
  1. Exit the application
  • Press q key to quit and save data automatically

Usage Instructions

  1. Positioning: Stand in front of your webcam with dumbbells, ensuring your entire upper body is visible
  2. Starting Position: Begin with arms fully extended downward (angles > 160°)
  3. Execution:
    • Curl both dumbbells upward simultaneously until elbows are fully bent (angles < 50°)
    • Return to starting position in a controlled manner
  4. Monitoring: Watch the real-time display for:
    • Rep count (green text)
    • Score (yellow text)
    • Left/right arm angles
    • Pose skeleton overlay

Output Features

  • Real-time Display: Full-screen interface showing:
    • Current repetition count
    • Total score
    • Individual arm angles
    • Pose landmarks and connections
  • Data Logging: CSV file automatically saved with timestamp containing:
    • All 33 pose landmarks (x, y, z coordinates + visibility)
    • Left and right arm angles for each frame
    • Cumulative rep count and score

File Structure

dumbbell_scoring/
├── run.py                 # Main application file
├── requirements.txt       # Python dependencies
├── README.md             # Project documentation
└── pose_data_YYYYMMDD_HHMMSS.csv  # Auto-generated data files

Requirements

The application requires the following Python packages:

  • opencv-python - Computer vision and video processing
  • mediapipe - Pose detection and landmark tracking
  • numpy - Mathematical calculations and array operations
  • pandas - Data storage and CSV export

Data Analysis

The generated CSV files can be used for:

  • Form analysis and improvement tracking
  • Repetition pattern analysis
  • Workout progress monitoring
  • Machine learning model training

Author

Ayub Ali Emon

  • Email: [email protected]
  • College of Computer Science
  • Shandong University of Science and Technology

License

This project is open source and available under the MIT License.

About

A computer vision demo application that detects and counts dumbbell bicep curl repetitions using OpenCV and MediaPipe.

Topics

Resources

License

Stars

Watchers

Forks