A Very Kinect Christmas
- Posted: Jan 16, 2012 at 6:00 AM
- 5,339 Views
- 3 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
While Christmas is behind us and the decorations put away, it's about that time to start going through our pictures. And there's few cuter pictures than this (plus it's a cool Kinect project too ![]()
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:
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
- identify the specific joint of the head of each skeleton
- calculate the relative coordinates of that joint before an image of the webcam
- 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.
Project Information URL: http://elbruno.com/2011/12/28/kinect-merry-christmas-with-kinect-and-visual-studio-2010-gift-of-the-valentino/, http://kinectmerrychristmas.codeplex.com/
Project Download URL: http://kinectmerrychristmas.codeplex.com/releases/view/79524
Project Source URL: http://kinectmerrychristmas.codeplex.com/SourceControl/list/changesets
Runs with Beta2? Yes
void KinectSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
canvasSkeleton.Children.Clear();
this.HideImageHats();
var skeletonId = 0;
foreach (var skeleton in e.SkeletonFrame.Skeletons.Where
(skeleton =>
SkeletonTrackingState.Tracked == skeleton.TrackingState))
{
skeletonId++;
this.DisplayImageHats(skeletonId);
PaintBones(skeleton);
PaintJoints(skeleton);
foreach (Joint joint in skeleton.Joints)
{
if (joint.ID != JointID.Head)
{
continue;
}
float depthX;
float depthY;
kinect.SkeletonEngine.SkeletonToDepthImage(joint.Position, out depthX, out depthY);
var depthPixelX = (int)Math.Max(0, Math.Min(depthX * CameraViewer.ActualWidth, CameraViewer.ActualWidth - 1));
var depthPixelY = (int)Math.Max(0, Math.Min(depthY * CameraViewer.ActualHeight, CameraViewer.ActualHeight - 1));
depthPixelY -= 20;
var newPosition = this.GetDisplayPosition(joint);
this.MoveImageHats(newPosition, skeletonId);
Debug.WriteLine(string.Format("{0} ", DateTime.Now.TimeOfDay));
Debug.WriteLine(string.Format(" X:{0} Y:{1}", joint.Position.X, joint.Position.Y));
Debug.WriteLine(string.Format(" W:{0} Z:{1}", joint.Position.W, joint.Position.Z));
Debug.WriteLine(string.Format(" SkeletonToDepthImage depthX:{0} depthY:{1}", depthX, depthY));
Debug.WriteLine(string.Format(" depthPixelX:{0} depthPixelY:{1}", depthPixelX, depthPixelY));
Debug.WriteLine(string.Format(" New position X:{0} Y:{1}", newPosition.X, newPosition.Y));
}
}
}
private Point GetDisplayPosition(Joint joint)
{
float depthX, depthY;
kinect.SkeletonEngine.SkeletonToDepthImage(joint.Position, out depthX, out depthY);
depthX = Math.Max(0, Math.Min(depthX * 320, 320)); //convert to 320, 240 space
depthY = Math.Max(0, Math.Min(depthY * 240, 240)); //convert to 320, 240 space
int colorX, colorY;
var iv = new ImageViewArea();
// only ImageResolution.Resolution640x480 is supported at this point
kinect.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, (int)depthX, (int)depthY, (short)0, out colorX, out colorY);
//colorX = colorX / 2;
//colorY = colorY / 2;
// map back to skeleton.Width & skeleton.Height
var newX = (int)(CameraViewer.ActualWidth * colorX / 640.0) - 30;
var intY = (int)(CameraViewer.ActualHeight * colorY / 480) - 30;
return new Point(newX, intY);
}
private void MoveImageHats(Point newPosition, int skeletonId)
{
if (skeletonId == 1)
{
Canvas.SetLeft(this.contentControlHat1, newPosition.X);
Canvas.SetTop(this.contentControlHat1, newPosition.Y);
}
if (skeletonId == 2)
{
Canvas.SetLeft(this.contentControlHat2, newPosition.X);
Canvas.SetTop(this.contentControlHat2, newPosition.Y);
}
}
private void DisplayImageHats(int skeletonId)
{
if (skeletonId == 1)
{
this.imageHat1.Visibility = Visibility.Visible;
}
if (skeletonId == 2)
{
this.imageHat2.Visibility = Visibility.Visible;
}
}
Contact Information:
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums,
or
Contact Us and let us know.
Follow the Discussion
Oops, something didn't work.
What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in. You need to be signed in to Channel 9 to use this feature.What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in and view them all on your notifications page.sign up for email notifications?
I totally loved this! I've been using the Xbox Controller and MS Robotics Studio with the Lego Mindstorms since Christmas and just got the Kinect USB Adapter in the mail today. This was our first app that we ran and it made taking down the tree a little less painful. Loved the app. Very creative and happy. On first try, we only seemed to get one hat at a time instead of 2. I haven't looked into it yet, but I'm sure it's me.
For others, we had to paste in the full path to free-christmas-powerpoint-background-11.jpg in the <ImageBrush ImageSource= node of the MainWindow.xaml file. This file can be found in the Images folder, alt+enter for properties, double click to grab the full path.
i m able to display tshirt in frnt f persn....
but how to change size of tshirt accordingly as a person moves back wrd nd frwrd in front of kinetic
Bjr, j'arrive pas à ouvrir le jeu, j'ai télécharge le code source et il y a toujours une exception qui s'affiche?!
Remove this comment
Remove this thread
close