Kinect SDK 1 - The Full Skeleton |
Written by Harry Fairhead | ||||
Page 2 of 3
Drawing the BodyNow that we have the video frame as a bitmap we can start to draw the skeleton on it. We need to retrieve the skeleton data. This is done in the usual way: SkeletonFrame SFrame = e.OpenSkeletonFrame(); Now we have the skeleton data in the Skeletons array we can step through each skeleton in the set and check its tracked status before processing it: foreach (Skeleton S in Skeletons) Now we have a skeleton in S we can use it to find the positions of any joint as we did in the previous chapter. Our next problem is to find the positions of each of the joints that makeup the "body" of the skeleton i.e. the torso. If you look at the diagram that gives the names of the joints you can see that we need the positions of the Head, Shoulder Center, Spine and Hip Center.
The positions of these four joints gives us the line of the torso and this is the line we need to draw connecting each of the joints in the correct order.. First we need the position of the head: SkeletonPoint Sloc = and we need to convert its position to pixel co-ordinates as described in the previous chapter: ColorImagePoint Cloc= So far so good but now we need the position of the ShoulderCenter joint and this means repeating everything we have just done and again for the spine and subsequent joints. We clearly need to package this code into a helper method: Point GetJoint(JointType j, Skeleton S) The only difference is that we are now returning the co-ordinates as a Point object rather than a ColorImagePoint. The reason for this is that the GDI drawing routines we are going to use accept Point object parameters. Now we have the helper we can plot the line between the head and the ShoulderCenter joints: Point p1=GetJoint(JointType.Head,S); where g is the graphics object associated with the Bitmap i.e.: Graphics g = Graphics.FromImage(bmap); Now if you run the program you would see a single red line drawn from the head to the shoulder. This is the first part of our skeleton drawing.
Drawing a Boneit 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( This will draw a line between the two specified Joints. So to draw the body all we need is: DrawBone( JointType.Head, This is all we need! If you run the program now you will see lines following the body of the users that are detected.
|