Adventures in Motion Capture: Using Kinect Data (Part 1)
July 1, 2016
Three weeks ago I wrote about my travails with setting up the Microsoft Kinect v2 sensor to record motion capture for my own game development needs. At the time, I mentioned I’d follow up with my experiences using the different motion capture software packages that are currently available. Instead, I’m back this week to write about my own spelunking into the data received directly from the Kinect itself: how to get that data and how to apply it to my own models.
So why the change in direction? Two reasons.
First, I’m a computer guy and I love playing around with new bits of kit. I became fascinated by the Kinect software development kit and wanted to have some fun with the data from the Kinect sensor myself.
Second, I did start to look at a number of motion capture packages out there and for various reasons found I either couldn’t use them or was unwilling to. One important factor was that after the difficulties I had getting the hardware set up, I wanted to make sure that any software I used would indeed work well. So before plunking down any money, I naturally wanted to give a demo/trial a go. Anyway, here’s a quick rundown of the ones I looked at:
- Brekel – Brekel’s trial version only allows for four seconds of recording time. I passed this one by as, given how my computer and Kinect sensor are currently positioned, I didn’t think I’d be able to start the recording and then get into position in time to actually capture any data. Ten seconds probably would have done it, but not four.
- nuiCapture – nuiCapture Animate has a thirty second record limit so I thought this one would work out for me. However, the software would not run on Windows 10, erroring out immediately. After a bit of further research, I found this software was released prior to the Kinect v2 sensor, so even if the software had run on Win 10, it’s unlikely it would have worked with the v2 sensor (having been developed for the Kinect 360 sensor instead).
- NI Mate – I gave the trial version for NI Mate a try and indeed it could use the Kinect sensor and bring data into it. However, I discovered the trial version doesn’t allow for saving data out to a file. Without the ability to save to a file I was unable to test the pipeline of recording data, applying it to my test model’s skeleton, and then trying it in game. Without “proof of pipeline” this was another application I had to pass by.
- Fastmocap – Quickly passed this one by as (a) it only supports the Kinect 360 sensor not the Kinect v2 sensor and (b) they oddly don’t have a trial version due to “some security reasons” (which sounds more than a little dodgy).
- Kinect BVH – Free motion capture software but it only works with the Kinect 360 sensor not the v2. Another pass.
- iPi Soft – I’ve read good things about this software but I decided to pass on giving it a try at this time. This software offers a 30 day trial after which it switches to a subscription pricing model. Now, I’m OK with plunking down a couple of hundred dollars for a good piece of software. I’m less OK with having to do that every year. I’m leaving this open as an option to look at in the future, but I’m passing over it for now (got to save that trial period for when I better know the requirements of what I’ll need for my game).
Skeletal Animation Basics
A little bit of preamble before we get to actually using data from the Kinect sensor. This is basic 3D animating stuff. If you’re looking into motion capture tools you’re probably already familiar with it, but if not…
![[A 3D model from Robyn HUD (WIP).]](images/skeleton01.gif)
A 3D model from Robyn HUD (WIP).
To start with, we have a 3D model of some sort that we want to animate. That model is made up of a bunch of vertices, or individual points in space that when connected give us a basic representation of what the model looks like. To animate the model we need to move where all those points in space are. For example, if we want to have a character holds its arm out in front of it, we swing up all the vertices that make up that arm.
![[All vertices related to the right arm rotate about the right shoulder.]](images/skeleton02.gif)
All vertices related to the right arm rotate about the right shoulder.
It would be a lot of very repetitive work to figure out how to move each vertex individually. However, we can simplify the amount of work needed by recognizing that vertices can be moved in batches. For example, when the bone of a real person’s upper arm moves, all the muscle and skin and goopy insides surrounding that bone move in the same way. Specifically, all of that material rotates through space as the person’s shoulder rotates.
It’s this idea of rotation that leads into skeletal animation. For our 3D model we can create a simple “skeleton” by defining points at each of the major places that can bend (rotate), like so:
![[A skeleton can be defined for a 3D model to reduce the number of points we have to worry about.]](images/skeleton03.gif)
A skeleton can be defined for a 3D model to reduce the number of points we have to worry about.
Those points represent the joints of our model’s skeletons. As a given joint rotates, we can rotate all the vertices related to it around that joint. We can also rotate the position of any joint attached to that joint. So if we rotate the shoulder of a model so that the upper arm is pointing forward, we can also apply the same kind of rotation to the lower arm so that it follows along. We can then add on an additional rotation to the lower arm to allow it to point up.
![[We just need to rotate the key joints and let the computer figure out the math for the vertices.]](images/skeleton04.gif)
We just need to rotate the key joints and let the computer figure out the math for the vertices.
Basically, if we have a list of rotations that we can apply to the different joints in a skeleton then we can cause a 3D model to move into whatever pose we require of it.
The Kinect Skeleton
The Kinect sensor is essentially a fancy camera that is able to “see” depth information. When a person walks into the view of the Kinect sensor, internally the sensor determines a basic skeleton for that person similar to how we could create a skeleton for a 3D character model as described above.
The closer our 3D character model’s skeleton resembles the Kinect’s skeleton, in terms of the joints used and how they’re connected to one another, the better our animation results will be. The Kinect v2 skeleton consists of 25 joints. Each joint is assigned a specific number to identify it. The Kinect skeleton is arranged as follows:
![[The Kinect v2 joint hierarchy.]](images/skeleton05.gif)
The Kinect v2 joint hierarchy.
It’s important to know the hierarchy of the joints. The ultimate parent of all joints is joint 0 SpineBase. Child joints spread outwards from the SpineBase joint. For example SpineMid, HipLeft and HipRight are all children of SpineBase. This will become important when we process the Kinect data in order to apply it to our own 3D models.
Important: As mentioned, the v2 sensor records data for 25 joints. The older Kinect v1 sensor (the one that is used with the Xbox 360) records fewer joints. This is why SpineShoulder (joint 20) seems to be out of place as far as its index number goes, because it was added into the skeleton for the v2 sensor and is not present in the v1 sensor’s skeleton.
The Kinect SDK Samples
One of the requirements of setting up the Kinect v2 sensor on a Windows machine is that the Kinect 2.0 SDK must be downloaded and installed. The fun thing about this is that the SDK includes a bunch of simple sample applications that highlight the different features of the Kinect. Typically these samples involve gathering some subset of the data from the Kinect and displaying it on screen. Among the samples there are applications for displaying the raw depth data the sensor sees, the joint and bone positions of people standing in front of the sensor, the regular video camera data from the sensor, facial recognition, and so on.
I was most interested in the joint and bone position data as that’s what’s needed to animate a 3D character. The SDK sample that captures and displays this data (in the form of an animated stick figure on screen) is the Body Basics application.
I won’t go through the Body Basics application line by line as that’s what the SDK sample code is for. However, in summary the sample application does the following:
- Connects to the Kinect sensor.
- Retrieves frames of 3D body data from the Kinect sensor.
- Converts the 3D body data into 2D monitor screen coordinates.
- Draws a stick figure skeleton using the converted 2D points.
- Closes the Kinect sensor when the application ends.
The deceptive thing with this sample application comes when converting the 3D data to 2D to be represented on screen. The Kinect tracks the joints of a person (knees, shoulders, elbows, etc.) as positions in three dimensional space and as rotations that indicate how those joints are bent. The sample application uses the positions of the joints as opposed to their rotations. This is fine if all we want to do is what the sample does, drawing where the joints are and then connecting the dots with lines.
However, as far as animation goes, what we really want is the rotation information. As I described in the Skeletal Animation Basics, what we’re after is a list of rotations that we can apply to each joint in order to pose our own 3D model. In this case, that list of orientations will be the orientations for each joint on the person the Kinect is observing.
Getting the joint orientations is actually very easy. The sample application retrieves an instance of the BodyFrame class for each frame recorded from the Kinect sensor. The BodyFrame class contains a getAndRefreshBodyData method which is used to retrieve a list of all the bodies in view of the camera for that frame. The Kinect automatically tracks up to six bodies in view, although it only tracks the skeleton data for two of those bodies.
Once the sample application has retrieved the list of bodies, which are instances of the Body class, it loops through all of them looking for the ones where the isTracked property is true. These are the bodies that skeleton information is available for.
At this point, the sample application then uses the joints property of the body it’s processing to determine the positions in 3D space of each joint. Those positions are mapped to 2D screen coordinates and a pseudo-skeleton is drawn for the body.
As mentioned, we want the rotation information, not the position information. The rotation data is also available to us off of Body objects we get from the sensor. Instead of accessing the joints property, we want to access the jointOrientations property.
The jointOrientations property is a list of the 25 joints the Kinect v2 sensor tracks. Each element in the list has two properties of its own:
- jointType – The number of the joint as shown in the Kinect Skeleton section above.
- orientation – A vector4 that is a quaternion representation of how the joint is rotated (quaternion’s are beyond the scope of this blog, suffice to say they’re a compact and easy way to represent and work with rotations in three dimensional space).
My first step in working with the Kinect data was to just get the basic orientation data written out to a file. I started with the original SDK example, but changed it so that on each frame it would stream out to a file the following the information:
- the number of tracked bodies seen that frame
- the 25 rotation quaternions in order from 0 to 24 for each tracked body
Getting the raw animation data out to a file was a critical first step. After all, in any final game, the animation data, properly cleaned and processed, will need to be read in from a file in order to be used by that game. But this blog’s getting long enough already. Pop back next week when I’ll go through the specifics of the Kinect joint orientations, how they should be applied to an actual 3D model, and a few other odds and ends along the way.
Previous: Sleuthhounds Animations? Check, Check, Not Check | Next: Adventures in Motion Capture: Using Kinect Data (Part 2)
Blog Posts
2025
April
04: Rolling Some Animations
March
07: Speaking and Moving
February
07: The Voices in Their Heads are Talking
January
03: Reputable Script Organization
2024
December
06: A Grab Bag of Stuff
November
08: The Recording Booth is Finished and then Some
September
06: The Recording Booth is Started
August
09: It’s All About the Dialog (Now)
July
05: Talking About Statistics
June
07: Broken Dialog Record
May
03: Finally Photos
April
05: Hint System 2.0
March
08: Flashing Back in Time
February
09: Inventory, Inventory Everywhere
January
05: Sleuthhounds Year Seven, Will it be the Last?
2023
December
01: Climbing the Rungs
November
03: Walking Through the Evolution of the Walkthrough
October
06: Look to Look
September
01: Sneaking at Sunset
August
04: Every Game Needs a Loot Box
July
07: Hamsterdam Exchange: Revisited
June
02: Dressings All Dressed Up
May
05: Ducts? Why Did it Have to be Ducts?
April
07: End of the Road
March
03: Daughter of the Boss
February
03: Den of the Boss
January
06: Where are We At? Where are We Going?
2022
December
02: Cutting the Way to Success
November
04: Maintaining the Ship
October
07: Once More Around the Promenade
September
02: Toilet Tank Humour
August
05: Uplifting: Combining 2D and 3D
July
01: A Moodier Room
June
01: Try Your Luck...Or Not
May
06: The Sky Deck: Almost but Not Quite There
April
01: A Clean Desk is a Sign of Dirty Drawers
March
04: Cable Management
February
04: The Doctor Will See You Now
January
07: The New Year is No Time for Lounging About
2021
December
03: Bridging the Gap
November
05: Captain's Log, Or Cabin
October
01: One Man's Treasure...
September
03: Rudder Way to Go
August
06: The Illusion of Depth
July
02: Streamlining Stairways for Players
June
04: Room with a View
May
07: States, Saves, and Simplifying Testing
April
02: Safety Features
March
05: When You Gotta Go
February
05: The Dining Room: Last of the Big Three
January
01: Boxing Day Sale at Sea
2020
December
04: You Gotta Have a Library
November
06: Pipes and Problems
October
02: A Sleuthhounds Message
September
25: It's a Room Sandwich
18: Writer's Room
11: Souvenirs at Sea
04: Cruise Cartography
August
28: Chocolate Shop, Er, Passenger Cabin
21: Place Your Wagers at the Pirate’s Chest Casino
14: Sometimes You Just Gotta Stop and Admire a Sunset
07: The Cruise Casino for Fun and Profit
July
31: Keep Fit and Have Fun
24: Even More Doors
17: Doors, Doors, and More Doors
10: Art Walk
03: Captain Windwhistler, to the Bridge
June
26: Doctor Seymour, to the Infirmary
19: Bilge is a Funny Word
12: There's No Money Laundering Here
05: A Pirate I was Meant To Be
May
29: You Gotta Have a Brig
22: Boring Backgrounds for the Staff
15: Theatre from on High
08: Theatre Crowding
01: In the Pool Any Time of the Day
April
24: The Crew Have to Sleep Too
17: Spring Time, Flowers Time
10: Cleaning Staff
03: Two Worlds
March
27: Kitchens, Spared No Expense
20: Cabins Day and Night
13: An Art Tour at Sea
06: The Pirate's Chest
February
28: Room with a View
21: Lock Picking Refined
07: The Gigantic Joanna
January
31: Updating the Safe
24: Interview Screenies
17: Burning Down Assets
10: Full Speed Ahead on Asset Creation
2019
December
20: Christmas Sale and Mini Mysteries
06: Generic Character Interactions
November
29: Locking the Gates - Preventing Characters from Wandering Amok
22: Side Quests Complete
15: Achievements to Prompt Replays
08: Interviews and Interludes
October
25: Halloween Sale and Mini Mysteries 2019
18: Fountains and Fortunes
11: Shifting the Blame Game
04: Streamlining the Audio Workflow
September
27: Hamsterdam Exchange
20: Streamline the Interface, Lower Production Time
13: Linking Ideas like a Golden Necklace
06: Beware of Geeks Bearing Gifts
August
16: Extra, Extra! Read All About the Extras!
09: Dressings of Fruits and Veggies
02: Sidling into Side Quests
July
26: Working on Workouts
19: How to Draw Cartoon Marble
12: AppCredits() = The End
05: Getting the Ending Right
June
28: The Problem with Balconies
21: Return of the Summer Sale and Mini Mysteries
14: The First Ending
07: Rewrites and Recodes
May
31: Choice and Consequence
24: Doctor Seymour Colourization
17: Sneaky, Sneaky
10: Play Time
03: Things to Do in Acts 1 to 3
April
26: The Changing Nature of Estimates
19: Escaping the Balcony (A Goldilocks Puzzle)
12: Facts more Fun than Fiction
05: Ramping Up Difficulty in an Adventure
March
29: Evolution of a Scene
22: Characters: Sources of Problems and Solutions
15: The Act 3 Countdown
08: Ducts, Why Did it Have to be Ducts?
01: Cheating in the Name of Narrative
February
22: Meet the Suspects - Edward Noble
15: Meet the Suspects - Doctor Michelle Seymour
08: Flashback Investigation
01: Milestone: Act 2 Done-ish
January
25: Letting the Player Fail
18: Meet the Suspects - Tobias Rotterdam
11: Adding another Layer to Note Reassembly
04: Meet the Suspects - Craig Holdfast
2018
December
28: New Free Games Section
21: Meet the Suspects - Carlotta Travail
19: Christmas Sale and Mini Mysteries
14: From Body Language to Sleuthhounds
07: Ludum Dare 43 - Body Language
November
30: Meet the Suspects - Carmichael Portly
23: Meet the Suspects - Marion Wood
16: Finding Focus
09: Safe Cracking
02: Meet the Suspects - Captain Warwick Windwhistler
October
25: Halloween Sale and Mini Mysteries
19: Meet the Suspects - Sir Reginald Price
12: Meet the Suspects - Joanna Price
05: Revising Rough Drafts
September
28: Light in the Dark
21: Animation Improvements - Realized
14: Animation Improvements - Design
07: Fainter and Fainter
August
31: A Splash of Colour
24: Paging Doctor Homes
17: Talking of Alternatives
10: Costume Party
03: Lock Picking
July
27: Act 2 from On High
20: Disruptive Director
13: Rolling, Rolling, Rolling
06: NPC Biographies
June
29: Design - Stepping Sideways to Move Forward
19: Summer Sale and Mini Mysteries
15: Mini Mysteries on the Way
01: Walk the Walk
May
25: Windows 10 Pen Woes, Part 2
18: Windows 10 Pen Woes, Part 1
11: SeaLeft FAQ
04: Milestone: Act I Done-ish
April
27: Saves, the Bookmarks of Games
20: NPCs Doing Their Own Thing
13: Homes and Ampson Together and Apart
06: Dialog as Interesting Gameplay, Take 3
March
30: Dialog as Interesting Gameplay, Take 2
23: Dialog as Interesting Gameplay, Take 1
16: Dialog: The Problem
09: Iterating on the Dining Room
02: Refining with Index Cards
February
23: Refining with Puzzle Dependency Charts
16: Refining Practically
09: Sleuthhounds Valentine's Sale
02: Refining Geographically
January
26: Feature Length Design Challenge
12: The New Sleuthhounds Cast
05: New Year, New Direction
2017
December
29: Distorting Voices - Muffled Neighbours
22: Merry Christmas, 2017
18: Announcing: Sleuthhounds - The Yuletide Tail
15: Sleuthhounds Holiday Sale
08: Distorting Voices - Old Time Phonograph
01: The Yuletide Tail Trailer
November
24: Yuletide comes Early
17: Christmas Countdown
10: Short Story Published: Rites and Responsibilities
03: The Halloween Deception - Post Mortem, Part 2
October
27: The Halloween Deception - Post Mortem, Part 1
20: On Sale: The Halloween Deception
13: Adding Depth to Drawers
06: Through the Doorway
September
29: Teamwork
22: Animating in the Rain
15: Let is Snow! Let it Snow!
08: NaNoWriMoPla 2017
01: Record Your Own Line
August
25: Sleuthhounds History
18: Sleuthhounds Series Summer Sale
11: Time for a Timeline
04: Save and Load: A Developer Tool
July
28: The Cast of Robyn HUD: The Guard(s)
21: HUD Hacking v2.0
14: Intro Revisions
07: Sounds Like Wood
June
30: Blending up a Table Saw
23: Moving Ideas Forward
16: Windows Were Meant to be Resized
09: Blueprints from Buildings
02: Expanded Scenes
May
26: Artifical Intelligence: Robyn
19: HUD Hacking
12: Robyn's Wheels
05: Deleted Scenes
April
28: The Cast of Robyn HUD: Robyn
21: Lights, Camera, Action: The Intro Scene
14: The Cast of Robyn HUD: Arthur
07: Adventures in Facial Capture: Using Kinect Data (Part 1)
March
31: Stairway to Gaming
24: The Sleuthhounds Effect
17: Cops Have Vans
10: Mini Models for Detail
03: Storylines in Twine
February
24: Planning a Game Narrative
17: Evolution of a Level: Texture
10: The Valentine's Vendetta Trailer
03: Robyn HUD: The Face
January
27: Robyn HUD: The Body
20: Robyn HUD: Start of Production
13: Evolution of a Level: Form
06: Countdown to Christmas Sleuthhounds has Begun
2016
December
23: Sleuthhounds of Christmas Yet to Come
16: Accessibility for Younger Audiences
09: Reality's Not All It's Cracked Up to Be
02: A Good Heist Requires a Good Plan
November
25: Artifical Intelligence: Guards
18: Artifical Intelligence: Bystanders
11: Unconventional Design Tools for Robyn HUD
04: Brainstorming
October
31: Announcing: Sleuthhounds - The Halloween Deception
28: Coming Soon: Sleuthhounds - The Halloween Deception
21: Nice to Haves, the Final Polish
14: The Halloween Deadline
07: Halloween Countdown
September
30: Cutting through Cutscenes
23: Life of the Party
16: What's in a Name?
09: Halloween End to End
02: Ludum Dare 36: Amelia Deerhart and the Elemental Temple
August
26: Crowd Considerations
19: Interaction Density
12: Puzzle Wrangling
05: Sleuthhounds, Top Priority
July
29: Adding 3D to a 2D Game
22: Does an Idea Have Legs?
15: Adventures in Motion Capture: Using Kinect Data (Part 3)
08: Adventures in Motion Capture: Using Kinect Data (Part 2)
01: Adventures in Motion Capture: Using Kinect Data (Part 1)
June
24: Sleuthhounds Animations? Check, Check, Not Check
17: Retro Tech: Quake 3 Light Volumes
10: Adventures in Motion Capture: The Hardware
03: Interactive Cutscenes: Adding Depth and Responsiveness
May
27: From Stealth to Robyn HUD
20: Sneaking into Stealth
13: Storytelling in Computer Games (Part 2 - Looking Forward)
06: Storytelling in Computer Games (Part 1 - Looking Back)
April
29: Walking Away from Windows 10
22: Code Name: Stealth
15: Using Game Tech Creatively
08: Game Accessibility: Visual Sound
01: Walking for Ideas and Creativity
March
25: Game Dev: Unintended Sophistication
18: A Sleuthhounds Trick or Treat in March?
11: Game Design: Success through Failure
04: Critical Equipment in Critical Condition
February
26: Semispheres - Support Your Local Game Dev
19: Post Project Completion Syndrome
14: Announcing: Sleuthhounds - The Valentine's Vendetta
12: Coming Soon: Sleuthhounds - The Valentine's Vendetta
05: Sleuthhounds Production Update - Implementing Two Characters
January
29: Sleuthhounds Production Update - Designing for Two Characters
22: So You Want to Make a Computer Game: The Path Leads On
15: How to Animate When You Don't Know How to Animate
08: So You Want to Make a Computer Game: Deploying
01: State of the Union, 2016
2015
December
25: So You Want to Make a Computer Game: Sound and Music
18: Ludum Dare 34: Rise of the Weeds
11: So You Want to Make a Computer Game: The Critical Path
04: An Hour of Code for Ludum Dare
November
27: So You Want to Make a Computer Game: Custom Artwork
20: Obfuscating NaNoWriMo Manuscripts
13: So You Want to Make a Computer Game: Inventory Items
06: Satin and Sutherland Return for NaNoWriMo
04: Announcing: Sleuthhounds - The Cursed Cannon
October
30: So You Want to Make a Computer Game: Interactivity
23: Coming Soon: Sleuthhounds - The Cursed Cannon
16: So You Want to Make a Computer Game: The Virtual World
09: NaNoWriMo Prelude: Be Creative
02: So You Want to Make a Computer Game: The Artwork
September
25: More Evolving: Tweaking the Sleuthhounds Timeline
18: So You Want to Make a Computer Game: The First Step
11: Sleuthhounds: The Cursed Cannon - It's the Final Countdown
04: Vampire Bites (Ludum Dare 33 Redux)
August
28: Ludum Dare 33: You are the Monster
21: Game Performance: It's the Software's Fault
14: Short Story Published: Where There's Thunder
07: Game Performance: It's the Hardware's Fault
July
31: CMYW - Support Your Local Game Dev
24: Is it Still Scope Creep if you Plan for It?
17: After a Game Engine, You Can Program Anything
10: An Avalanche of Done-ness
03: Sleuthhounds with Style
June
26: Sources of Gameplay - Assets Versus Emergent Behavior
19: Benefit of Writing Comics: Humour or Humor
12: Evolving: Reimagining the Sleuthhounds Story Board as a Timeline
05: Evaluating: Play Testing the Sleuthhounds Story Board
May
29: Magic and Public Speaking
22: Implementation: Realizing the Sleuthhounds Story Board
15: Benefit of Writing Comics: Pacey Dialog
08: eBook Publishers: Final Comparison
01: Design: Brainstorming the Sleuthhounds Story Board
April
24: Analysis: Dialog Trees in Adventure Games
17: Benefit of Writing Comics: Writing Tight
10: eBook Publishers: Apple
03: Sleuthhounds Production Update - The Critical Path, Designing from the End
March
27: Sleuthhounds Production Update - Games Have Rough Drafts Too
20: Benefit of Writing Comics: Long-term Story Planning
13: eBook Publishers: Google
06: Announcing: Sleuthhounds - The Unlocked Room
February
27: Coming Soon: Sleuthhounds - The Unlocked Room (The First Game Demo)
20: Benefit of Writing Comics: Character Growth
13: eBook Publishers: Kobo
06: From Case Files to Sleuthhounds: Evolution of a Computer Game
January
30: Deadlines and the Estimates that Make Them (OR Why the Sleuthhounds Demo isn't Ready)
23: Adventures in Canadian ISBNs
16: Benefits of Writing Comics: Releasing Material
09: eBook Publishers: Amazon
02: New Year's Resolutions: Making Time
2014
December
26: Quack V – The Unwrapped Present
19: Benefit of Writing Comics: Constant, Regular Practice
12: What’s next? Elementary, my dear Ampson. Sleuthhounds!
05: Announcing: Satin & Sutherland – The Golden Curse
November
28: Coming Soon: Satin & Sutherland – The Golden Curse
21: Enter the Cubes
14: Covers, Judging By
07: Hello, World!