A Python-based motion capture system that uses computer vision to detect human pose and track a ball, generating data for use in Unity animations and visualizations. The project includes both the Python detection scripts and Unity C# scripts for rendering.
![]()
This project provides tools to:
The system supports both real-time preview and offline processing of video files, with options for basic or advanced ball interpolation.
git clone https://github.com/donsolo-khalifa/FootballKeyPointsExtraction.git
cd FootballKeyPointsExtraction
```
### Project Structure
```text
FootballKeyPointsExtraction/
├── python # Motion capture & tracking
│ ├── main.py # Real-time visualization
│ ├── motionCapture.py # Basic capture → `AnimationFile.txt`
│ └── ballInterpolationMC.py # Two-pass ball interpolation
├── C# # Unity integration & rendering
│ ├── AnimationCode.cs # Applies data to joints & ball
│ └── SkeletonRenderer.cs # Draws skeleton lines
├── requirements.txt
└── .gitignore
main.py - Real-time visualization of pose estimation and ball trackingmotionCapture.py - Basic motion capture that processes video and saves keypoints to a text fileballInterpolationMC.py - Advanced motion capture with ball position interpolation for smoother animationsAnimationCode.cs - Script for reading animation data and applying it to skeleton and ballSkeletonRenderer.cs - Script for rendering the skeleton by drawing lines between jointspip install -r requirements.txt
opencv-python
cvzone
ultralytics
tqdm
numpy
To preview the pose and ball detection in real-time:
python main.py
Press 'q' to exit the preview.
For simple motion capture without ball interpolation:
python motionCapture.py
This will process the video file, detect pose keypoints and ball position, and save the data to AnimationFile.txt.
For motion capture with ball interpolation (smoother ball tracking):
python ballInterpolationMC.py
This uses a two-pass approach:
AnimationFile.txtThe AnimationFile.txt contains comma-separated values for each frame:
x,y,zx,y,zCoordinates are normalized:
The project includes ready-to-use Unity scripts for rendering the captured motion:
AnimationFile.txt into your Unity project's Assets folderSet up the hierarchy:
Create an empty GameObject as a parent and rename it to Manager
BodyBody (one for each joint)BallCreate an empty GameObject as a parent and rename it to SkeletonRenderer
Add the scripts:
AnimationCode.cs to the Manager GameObjectAssign all 33 joint 3D objects (Spheres) to the Body array in the Inspector
> Note: Tip for mass assigning joints:
> - Lock the Inspector window (click the lock icon in the top-right of the Inspector)
> - Select all 33 joints (Spheres) in the Hierarchy by clicking the first one, then Shift+click the last one
> - Drag the entire selection into the Body array field in the Inspector
This will automatically populate all array elements in the correct order
Assign the ball Sphere to the Ball reference
For skeleton visualization:
SkeletonRenderer.cs to the SkeletonRenderer GameObject Body fieldlinePrefab fieldAnimationFile.txtThread.Sleep(30) value in AnimationCode.cs to change animation speed_connections array in SkeletonRenderer.cs to change which joints are connectedcv2.VideoCapture(0) instead of cv2.VideoCapture('vida.mp4') video_path in the scripts to use a different video fileBALL_CLASS_ID if tracking a different object (32 is sports ball in COCO dataset)MAX_FRAMES_TO_KEEP in real-time applications to control how long a ball position is retained when detection failsballInterpolationMC.py provides smoother ball tracking but is not suitable for real-time applicationsmotionCapture.py or implement simple interpolation with a single-pass approach$ claude mcp add FootballKeyPointsExtraction \
-- python -m otcore.mcp_server <graph>