Kinect SDK 1 - Skeletons
Written by Mike James   
Article Index
Kinect SDK 1 - Skeletons
Using the GDI
Joints
From 3D to 2D

From 3D to 2D

First we need to convert the 3D skeleton co-ordinates into 2D color image co-ordinates:

ColorImagePoint Cloc = 
sensor.MapSkeletonPointToColor(Sloc,
ColorImageFormat.RgbResolution640x480Fps30);

We now have the x,y pixel co-ordinate of the Head in the video bitmap stored as properties of the ColorImagePoint. 

Assuming we have a method called  markAtPoint(ColorImagePoint p, Bitmap bmp)

which will draw an ellipse centered at the location, we can complete the program with:

  markAtPoint(Cloc, bmap);
}
}

The MarkAtPoint method simply uses the GDI to draw an ellipse:

void markAtPoint(ColorImagePoint p, 
Bitmap bmp)
{
Graphics g = Graphics.FromImage(bmp);
g.DrawEllipse(Pens.Red,
new Rectangle(p.X - 20, p.Y - 20, 40, 40));
}

Now if you run the program you should see a small red ellipses appear to mark the head of the players.

 

sample

 

The complete FrameReady event handler is:

void FramesReady(object sender, 
AllFramesReadyEventArgs e)
{
ColorImageFrame VFrame =
e.OpenColorImageFrame();
if (VFrame == null) return;
Bitmap bmap = ImageToBitmap(VFrame);
SkeletonFrame SFrame = e.OpenSkeletonFrame();
if (SFrame == null) return;
Skeleton[] Skeletons =
new Skeleton[SFrame.SkeletonArrayLength];
SFrame.CopySkeletonDataTo(Skeletons);
foreach (Skeleton S in Skeletons)
{
if (S.TrackingState ==
SkeletonTrackingState.Tracked)
{
SkeletonPoint Sloc =
S.Joints[JointType.Head].Position;
ColorImagePoint Cloc =
sensor.MapSkeletonPointToColor(Sloc,
ColorImageFormat.RgbResolution640x480Fps30);
markAtPoint(Cloc, bmap);
}
}
pictureBox1.Image = bmap;
}

Once you have seen how to track a head the rest of the body is no problem and you will be surprised at how rarely you actually need to draw a skeleton corresponding to where the player is - which is the topic of the next chapter.

 

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

Practical Windows Kinect in C#
Chapter List

  1. Introduction to Kinect
  2. Getting started with Microsoft Kinect SDK 1
  3. Using the Depth Sensor
  4. The Player Index
  5. Depth and Video Space
  6. Skeletons
  7. The Full Skeleton
  8. A 3D Point Cloud

 

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.

 

Further reading:

Avatar Kinect - a holodeck replacement

A Kinect Princess Leia hologram in realtime

Kinect augmented reality x-ray (video)

Kinect flies

Kinect plus a glass wedge gives ...

Kinect makes you Superman

Kinect goes self aware - a warning

Kinect for Microsoft Robots

Kinect knows what you are doing...

 

<ASIN:B006UIS53K@COM>

<ASIN:B0078LMS72@UK>

<ASIN:B002BSA298@COM>

<ASIN:B0036DDW2G@UK>

<ASIN:B0036DDW2G@FR>

<ASIN:B002BSA298@CA>

<ASIN:B003H4QT7Y@DE>

<ASIN:B00499DBCW@IT>