Personal AI Trainer
π Overview
Use pose estimation to judge in real time whether a workout movement is correct: with a squat as the example, it computes the changing angles of the hip, knee, and ankle joints, checks whether the range and the tempo are right, and counts reps live.
Built on the Pose Estimation project, it adds joint-angle maths and a movement state machine (down / up / count) - a model example of computer vision solving a real problem.
π§° What you need
- Computer + camera
- Python 3.7+ environment
- pip install: opencv-python, mediapipe, cvzone, numpy
- Optional: a yoga mat and room to frame your full body
π§ Step by step
Pose detection basics
Use PoseModule to get the 33 body keypoints in real time
Confirm the indices of the hip, knee, and ankle keypoints involved in a squat
Compute joint angles
Compute the angle formed by three points (hip-knee-ankle, for example)
Write it as a generic function: three coordinates in, angle out
Determine the phase
A large knee angle means standing, a small one means squatting
Define rules such as 0-90 degrees being the down phase
Counting logic
State machine: stand, squat, stand counts as one rep
Add hysteresis: stay near the threshold for a short while before switching state
Form warnings
Warn when an angle looks wrong (knees caving in, for example)
Show text and a progress bar on the frame
Support more exercises
Bicep curls look at the elbow, leg raises at the hip
Parameterise the movement rules so one framework covers many exercises
π‘ Tips
- Filming from the side gives the friendliest angle maths; a front view suffers from self-occlusion
- Give the counting threshold hysteresis (a different entry and exit threshold) to stop it flickering at the boundary
- Plotting the angle over time as a line chart helps you calibrate the rules