Build an AI Tennis Coach¶
| Category | Creative & Real-World AI Builds |
| Status | ๐ก Partially completed |
| Repo | nextwork-build-an-ai-tennis-coach |
| Original NextWork guide | nextwork.ai |
Learning project
Practice work following a NextWork guide, separate from my production projects.
๐ NextWork learning project. This is a practice project I built while working through NextWork's Build an AI Tennis Coach guide. It is part of my Learning portfolio and is fully separate from my production projects.
Category: Learning โบ Creative & Real-World AI Builds
Status: ๐ก Partially completed
Overview¶
Body landmarks from ordinary video can give repeatable stroke measures, but only if the footage allows it. This repo measures strokes in a CC-licensed coaching video and shows, with numbers, why that footage can't support a player-vs-pro verdict.
Summary¶
My own pose analyser (swing_analyzer.py, MediaPipe Pose Landmarker + OpenCV) ran on freely licensed Wikimedia Commons footage, because nobody filmed their own strokes. It finds strokes from hitting-wrist speed peaks and measures wrist speed, rough shoulder and hip turn, knee flex and wrist position in torso lengths. It wrote annotated videos and per-stroke CSVs: 17 forehand, 19 backhand and 6 pro rows. A screening rule flagged 1+1+0 rows as cuts or glitches. My report says the player-vs-pro comparison is invalid: the footage is edited, the speed is unknown and the camera angles differ. So no cue is supported, and no retest was done. The secret mission wasn't done (no 10-rep footage).
The checks behind this are in docs/verification.txt.
Skills & tools¶
MediaPipe Pose Landmarker, OpenCV, Signal peak detection, Data screening, Evidence-based reporting, ffmpeg
What I built¶
swing_analyzer.py: reads poses frame by frame, finds the hitting wrist's speed peaks (at least 0.8 s apart and above the median), and measures each stroke scaled by torso length. That scale stays steady side-on, where shoulder width collapses. Turn is estimated from foreshortening, as arccos(p10/p90 of apparent width).outputs/{player_forehand,player_backhand,pro_rally}_annotated.mp4(skeleton, speed bar, stroke counter) +_strokes.csv; contact sheets indocs/*_sheet.png; console output indocs/analyzer-run.txt(pose found in 94% / 91% / 100% of frames).tools/screen_rows.pyโoutputs/*_screened.csv+outputs/screened_medians.md: a row is flagged if the wrist moves over 25 torso/s (a camera cut) or lands over 2.5 torso lengths from the hips.outputs/coaching_report.md: my report. It gives the medians and the reasons the comparison is invalid, says no cue is supported, and lists what footage a real comparison needs.FOOTAGE.md: sources and licences.
How to run¶
uv venv --python 3.12 && uv pip install -r requirements.txt
# pose model (not committed): pose_landmarker_heavy.task from the MediaPipe model page, saved to ~/.nw-tennis/pose_landmarker.task
uv run python swing_analyzer.py videos/baseline_forehand.mp4 --name player_forehand --strokes 18
uv run python swing_analyzer.py videos/baseline_backhand.mp4 --name player_backhand --strokes 19
uv run python swing_analyzer.py videos/pro_rally.mp4 --name pro_rally --strokes 6
python tools/screen_rows.py player_forehand player_backhand pro_rally
Verification¶
I ran the verification command on 2026-12-03. The full output is in docs/verification.txt.
python3 -m py_compile swing_analyzer.py tools/screen_rows.py && python3 -c "import csv,os;n={k:list(csv.DictReader(open(f'outputs/{k}_screened.csv'))) for k in ['player_forehand','player_backhand','pro_rally']};assert [len(v) for v in n.values()]==[17,19,6];assert [sum(r['flagged']=='no' for r in v) for v in n.values()]==[16,18,6];assert all(os.path.getsize(f'outputs/{k}_annotated.mp4')>100000 for k in n);t=open('outputs/coaching_report.md').read();assert 'no coaching cue is supported' in t;print('TENNIS OK')"
Notes¶
Footage: EVD-tenis-003.ogv (User:Evdcoldeportes, CC BY-SA 2.5 CO) and 'Maria Sharapova on Amelia Island.ogv' (javajoba / Jack Kennard, CC BY 2.0), both from Wikimedia Commons, cut and re-encoded as FOOTAGE.md describes. The derived videos are under the same licences. The pose model isn't committed. An earlier version of this repo used the guide's scripts; they were removed on 3 Dec 2026 and every output was regenerated with my analyser.
What isn't done, and why¶
No footage of the learner: a coaching-school demonstrator stands in, and the clips have cuts and possibly slow motion. There's no same-angle pro reference, so the comparison and the one-cue output are unsupported, and no practice retest was done. Claude Code wasn't used. The secret mission (10 reps of another movement) wasn't done: the freely licensed clips have only 1โ2 reps.
Original project: https://nextwork.ai/projects/f822c2ab-b535-4293-9fe7-fa982f46ed4f ยท Part of my NextWork Learning portfolio (hub).
Verification output¶
From docs/verification.txt:
$ python3 -m py_compile swing_analyzer.py tools/screen_rows.py && python3 -c "import csv,os;n={k:list(csv.DictReader(open(f'outputs/{k}_screened.csv'))) for k in ['player_forehand','player_backhand','pro_rally']};assert [len(v) for v in n.values()]==[17,19,6];assert [sum(r['flagged']=='no' for r in v) for v in n.values()]==[16,18,6];assert all(os.path.getsize(f'outputs/{k}_annotated.mp4')>100000 for k in n);t=open('outputs/coaching_report.md').read();assert 'no coaching cue is supported' in t;print('TENNIS OK')"
TENNIS OK
[exit code 0]