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.
- 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
- 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°
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/π)
- Python 3.7 or higher
- Webcam
- Windows/macOS/Linux
- Clone the repository
git clone https://github.com/alfa-echo-niner-ait/dumbbell_scoring.git
cd dumbbell_scoring- Create virtual environment
# On Windows
python -m venv venv
venv\Scripts\activate
# On macOS/Linux
python3 -m venv venv
source venv/bin/activate- Install dependencies
pip install -r requirements.txt- Run the application
python run.py- Exit the application
- Press
qkey to quit and save data automatically
- Positioning: Stand in front of your webcam with dumbbells, ensuring your entire upper body is visible
- Starting Position: Begin with arms fully extended downward (angles > 160°)
- Execution:
- Curl both dumbbells upward simultaneously until elbows are fully bent (angles < 50°)
- Return to starting position in a controlled manner
- Monitoring: Watch the real-time display for:
- Rep count (green text)
- Score (yellow text)
- Left/right arm angles
- Pose skeleton overlay
- 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
dumbbell_scoring/
├── run.py # Main application file
├── requirements.txt # Python dependencies
├── README.md # Project documentation
└── pose_data_YYYYMMDD_HHMMSS.csv # Auto-generated data files
The application requires the following Python packages:
opencv-python- Computer vision and video processingmediapipe- Pose detection and landmark trackingnumpy- Mathematical calculations and array operationspandas- Data storage and CSV export
The generated CSV files can be used for:
- Form analysis and improvement tracking
- Repetition pattern analysis
- Workout progress monitoring
- Machine learning model training
Ayub Ali Emon
- Email: [email protected]
- College of Computer Science
- Shandong University of Science and Technology
This project is open source and available under the MIT License.