Skip to content

About

Computer-vision experiment that scores athletic movement from video: MediaPipe pose landmarks to joint angles to a two-headed LSTM.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Action Precision Analyzer

Score how cleanly a strike is thrown from an ordinary phone video, with no wearables or sensors.

The pipeline tracks the body with MediaPipe Pose, turns the landmarks into joint angles and their motion over time, and feeds the sequence to a two-headed LSTM that predicts both an execution-precision score and the strike type.

Status: a college learning project (2024–25), built before my first engineering job. It proves the pipeline end to end; it is not a validated judge of technique. See Limitations.

Case study: amal-antony-dev.vercel.app


How it works

video ──► frames ──► MediaPipe Pose (33 landmarks) ──► 5 joint angles per frame
                                                          │
                                   speed + acceleration ◄─┘  (frame-to-frame differences)
                                                          │
                              30 frames × 15 features ────► LSTM(64) ► LSTM(64) ► Dense(32)
                                                                                 ├─► precision (regression)
                                                                                 └─► strike type (softmax)
  1. Pose to angles. OpenCV reads each video into frames and MediaPipe Pose extracts 33 landmarks per frame. Shoulder, elbow, wrist, torso and hip points become five angles: shoulder flexion, elbow flexion, wrist angle, torso rotation and hip–shoulder alignment. Angles don't depend on where the person stands in the frame.
  2. Motion features. Every clip is fixed to 30 frames (padded or truncated). Frame-to-frame differences add angular speed and acceleration, giving 15 features per frame, min–max scaled before training.
  3. Model. Two stacked 64-unit LSTM layers and a 32-unit dense layer feed two outputs: a regression head for precision (mean-squared error) and a softmax head for strike type (cross-entropy), trained jointly with Adam for 50 epochs on an 80/20 split.
  4. Exploration. Per-feature mean and variance checks flagged low-signal angles; heatmaps and line plots show how each angle unfolds across the 30 frames of a jab.

Repository layout

File What it does
Feature_extraction.py Reads every video in Dataset/actions/, extracts landmarks and angles, writes x.json
lstmTraining.py Adds speed and acceleration, scales features, trains the two-headed LSTM, saves lstm_model.h5
predictionFeatureExtraction.py Runs the same extraction on one new video, writes x_pred.json
prediction.py Loads lstm_model.h5 and prints the precision score and strike-type probabilities
mean_variance.py, heatmap.py, linePlot.py Feature statistics and plots
x.json, y.json, x_pred.json Extracted features and labels used for training and the sample prediction
lstm_model.h5 The trained model

Run it

Python 3.10+ is recommended.

pip install opencv-python mediapipe numpy scikit-learn tensorflow matplotlib seaborn

# 1. Extract features from your training clips (put them in Dataset/actions/)
python Feature_extraction.py

# 2. Train
python lstmTraining.py

# 3. Predict on a new clip: set video_path in predictionFeatureExtraction.py first
python predictionFeatureExtraction.py
python prediction.py

Limitations

Worth being upfront about what this is:

  • Tiny, one-class dataset. 25 training clips, all jabs, so the strike-type head has nothing real to separate.
  • Placeholder labels. Precision labels were values between 0.63 and 0.80, not ratings from a coach, so the model can't learn what good technique looks like.
  • Possible leakage. Train and test are split by clip, not by person.
  • Scaler refit at prediction time instead of reusing the one fitted during training.
  • Image mode, not video mode, in MediaPipe, so tracking doesn't carry across frames.

What I'd do now

Collect coach-rated clips across several strike types, split by person, save and reuse the fitted scaler, switch MediaPipe to video mode, and turn the scripts into one tested package with a proper evaluation report.

Tech

Python · OpenCV · MediaPipe · TensorFlow/Keras · NumPy · scikit-learn · Matplotlib · Seaborn

About

Computer-vision experiment that scores athletic movement from video: MediaPipe pose landmarks to joint angles to a two-headed LSTM.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages