Getting started with Microsoft Kinect SDK - The Full Skeleton
Written by Mike James   
Monday, 23 January 2012
Article Index
Getting started with Microsoft Kinect SDK - The Full Skeleton
Drawing the body
Joining the Bones

 

Drawing a Bone

it should be obvious that what we have to do next is draw a line between ShoulderCenter and Spine. Clearly this is just a repeat of what we have already done so this suggests another helper function:

void DrawBone(JointID j1,
JointID j2,
SkeletonData data,
Graphics g)
{
Point p1=GetJoint(j1,data);
Point p2 = GetJoint(j2, data);
g.DrawLine(Pens.Red, p1, p2);
}

This will draw a line between the two specified Joints. So to draw the body all we need is:

DrawBone(JointID.Head, 
JointID.ShoulderCenter, data, g);
DrawBone(JointID.ShoulderCenter,
JointID.Spine, data, g);
DrawBone(JointID.Spine,
JointID.HipCenter,data, g);

This is all we need!

If you run the program now you will see lines following the body.

Now that you have seen this much adding two legs should be easy:

//Left leg
DrawBone(JointID.HipCenter,
JointID.HipLeft,data, g);
DrawBone(JointID.HipLeft,
JointID.KneeLeft, data, g);
DrawBone(JointID.KneeLeft,
JointID.AnkleLeft, data, g);
DrawBone(JointID.AnkleLeft,
JointID.FootLeft, data, g);
//Right Leg
DrawBone(JointID.HipCenter,
JointID.HipRight,data, g);
DrawBone(JointID.HipRight,
JointID.KneeRight, data, g);
DrawBone(JointID.KneeRight,
JointID.AnkleRight, data, g);
DrawBone(JointID.AnkleRight,
JointID.FootRight, data, g);

 

All we have left to do is to add the two arms:

//Left Arm
DrawBone(JointID.ShoulderCenter,
JointID.ShoulderLeft, data, g);
DrawBone(JointID.ShoulderLeft,
JointID.ElbowLeft, data, g);
DrawBone(JointID.ElbowLeft,
JointID.WristLeft, data, g);
DrawBone(JointID.WristLeft,
JointID.HandLeft, data, g);
//Right Arm
DrawBone(JointID.ShoulderCenter,
JointID.ShoulderRight, data, g);
DrawBone(JointID.ShoulderRight,
JointID.ElbowRight, data, g);
DrawBone(JointID.ElbowRight,
JointID.WristRight, data, g);
DrawBone(JointID.WristRight,
JointID.HandRight, data, g);

Now if you run the program you will see a complete skeleton plot.

You can argue that there are better ways to organize the code but you have to have a list of the joints you want to draw lines between somewhere.

If you want to try taking it further why not change the drawing of the head for an ellipse and a rectangle for the body. It is all fairly easy.

Articles on the Microsoft Kinect SDK

  1. Getting started with Microsoft Kinect SDK
  2. Depth
  3. Player index
  4. Depth and Video space
  5. Skeletons
  6. The Full Skeleton (this article)

Next Time: Audio

 

You can download the code for the Windows Forms version of this program from the CodeBin (note you have to register first).

 

raspberry pi books

 

Comments




or email your comment to: comments@i-programmer.info

 

To be informed about new articles on I Programmer, subscribe to the RSS feed, follow us on Google+, Twitter, Linkedin or Facebook or sign up for our weekly newsletter.



Last Updated ( Monday, 06 February 2012 )