[#KINECT] Merry Christmas with Kinect and Visual Studio 2010 (gift of the Valentino)

image

Hi,

in these days of festivities, when you join the side 2 dwarves wanting to play, you got the kinect connected to the PC and the SDK that you strange, at the very least you get is something like the following:

image

An application for every person that appears on WebCam puts a Santa Claus Cap!!!!

Disclaimer: as they can be seen in the screenshot, in addition to the view of the WebCam I am showing the skeleton, but just as he gave a ray of sunshine to my dwarf in the arm, therefore not recognized him!

As well, after several post about Kinect, today the challenge was as follows

  1. identify the specific joint of the head of each skeleton
  2. calculate the relative coordinates of that joint before an image of the webcam
  3. paint a Santa Hat on webcam

The first point is easily solved once we iteramos by the skeletons recognized in mode Trackeable (lines 6 to 9), we can iterate between the Joints of the skeleton and verify that it is the head compared with [JointID.Head] (line 17).

Once identified the head Joint we come to the 2nd point which is a bit more complicated. Function GetDisplayPosition() (line 27) is in charge for the conversion of the position of the Joint to relative location in the image. The following capabilities of the SDK are used to this

SkeletonEngine.SkeletonToDepthImage () using this function we can know the relative location in “depth” of a joint.

NuiCamera.GetColorPixelCoordinatesFromDepthPixel () using this function, we can discover the position at coordinates x/Y from the depth we obtained earlier.

In both cases, it must make some adjustments on the one hand the webcam image is 640 * 480 resolution and depth capacity is only 320 * 240. But hey, with these few lines already we can define the specific location of our head and paint a SantaHat therein.

   1: void KinectSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)

   2: {

   3:     canvasSkeleton.Children.Clear();

   4:     this.HideImageHats();

   5:     var skeletonId = 0;

   6:     foreach (var skeleton in e.SkeletonFrame.Skeletons.Where

   7:                   (skeleton =>

   8:                             SkeletonTrackingState.Tracked == skeleton.TrackingState))

   9:     {

  10:         skeletonId++;

  11:         this.DisplayImageHats(skeletonId);

  12:         PaintBones(skeleton);

  13:         PaintJoints(skeleton);

  14:  

  15:         foreach (Joint joint in skeleton.Joints)

  16:         {

  17:             if (joint.ID != JointID.Head)

  18:             {

  19:                 continue;

  20:             }

  21:             var newPosition = this.GetDisplayPosition(joint);

  22:             this.MoveImageHats(newPosition, skeletonId);

  23:         }

  24:     }

  25: }

  26:  

  27: private Point GetDisplayPosition(Joint joint)

  28: {

  29:     float depthX, depthY;

  30:     kinect.SkeletonEngine.SkeletonToDepthImage(joint.Position, out depthX, out depthY);

  31:     depthX = Math.Max(0, Math.Min(depthX * 320, 320));

  32:     depthY = Math.Max(0, Math.Min(depthY * 240, 240));

  33:     int colorX, colorY;

  34:     var iv = new ImageViewArea();

  35:     kinect.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, (int)depthX, (int)depthY, (short)0, out colorX, out colorY);

  36:     var newX = (int)(CameraViewer.ActualWidth * colorX / 640.0) - 30;

  37:     var intY = (int)(CameraViewer.ActualHeight * colorY / 480) - 30;

  38:     return new Point(newX, intY);

  39: }

 

This time I changed the mode of publication and if you want to download the code can do since CodePlex fromhttp://kinectmerrychristmas.codeplex.com/ .

If you already have a Kinect, SDK and wanted to test the application, you can install it directly fromhttp://kinectmerrychristmas.codeplex.com/releases/79524/clickOnce/ElBruno.MerryChristmas.application

 

Greetings @ Home and Merry Christmas

The Bruno

References:

Advertisements

One thought on “[#KINECT] Merry Christmas with Kinect and Visual Studio 2010 (gift of the Valentino)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s