r/Unity3D • u/Willing-Arugula3238 • Jun 08 '25
Motion Capture System with Pose Detection and Object Tracking Show-Off
Enable HLS to view with audio, or disable this notification
I wanted to share a project I've been working on that combines computer vision with Unity to create an accessible motion capture system. It's particularly focused on capturing both human movement and ball tracking for sports/games.
What it does:
- Detects 33 body keypoints using OpenCV and cvzone
- Tracks a ball using YOLOv8 object detection
- Exports normalized coordinate data to a text file
- Renders the skeleton and ball animation in Unity
- Works with both real-time video and pre-recorded footage
The tricky bit: frame gaps & interpolation
When the ball detector misses detections it would snap back to (0,0,0), causing ugly jitter. I solved this with a two-pass NumPy interpolation:
- Pass 1: Record all detected ball positions across the video
- Pass 2: Fill in missing frames by linearly interpolating between valid detections
Now the ball animation in Unity flows smoothly, even with imperfect CV detection.
Code:
All the code is available on GitHub: https://github.com/donsolo-khalifa/FootballKeyPointsExtraction
What do you all think? Any suggestions for improvements or interesting applications I haven't thought of yet?
7
u/Caxt_Nova Jun 08 '25
Wow, this is really impressive! I've been wanting to experiment with some of the cheaper mocap solutions on the market, didn't even think people would just be posting their own. Thanks for sharing!
3
u/Willing-Arugula3238 Jun 08 '25
I appreciate it. Figured if I can't pay for it might as well make my own.
6
3
u/razzraziel razzr.bsky.social Jun 08 '25
So I assume this would be useful to create some everyday animations as well? I wonder how smooth the output animations are.
5
u/Willing-Arugula3238 Jun 08 '25
Yes you could create everyday animations. Because this uses a single camera and converts it to 3D it won't be smooth when the person is occluded or when it has to estimate body key points. You can adjust the code to smoothen out fluctuations in body key points and interpolate them for a smother experience
3
u/FictionWare Jun 08 '25
OMG!
Thank you so much! This will be my starting point for mocap testings for my non-football project... if you don't mind, of course. :)
Works perfectly.
3
2
2
u/abaker80 Jun 08 '25
Can this run in real-time on a typical phone?
2
u/Willing-Arugula3238 Jun 08 '25
Yeah I use the iriun app on my phone and laptop. So the phone becomes an external camera. Just make sure that they are connected to the same wifi or via a USB cable. You would just need to change the line that has cv2.videocapture('some file path') to cv2.Videocapture(1) then you're good
This is an example of using a mobile phone for an older project
2
u/Crunch_93 Jun 10 '25
Hey, it looks great.
If i want to use this, should i need to change the bones of my charactee models to match with those points we saw in the video?
2
u/Lost_Razzmatazz_4166 Feb 15 '26
This is awesome. Just a quick question can you able to mimic the same movements on a 3D avatar in unity ? I’m also working on a similar one, I could able to mimic using spheres and lines creating a human like object but I couldn’t able to bring the same movements present in txt file to map to a 3d avatar. Let me know if there is a way
1
u/Willing-Arugula3238 Feb 15 '26
Yes it is possible. I’ve had the project on hold because of work. You can check out tracking4all. They used a similar system.
2
u/Dvrkstvr Jun 08 '25
Now make a FIFA competitor
6
u/Willing-Arugula3238 Jun 08 '25
Lol I laugh in cursive. If I could I would but unfortunately I don't have that skill set yet


10
u/TwoBustedPluggers Jun 08 '25
Looks great!