Displaying Skeletal joints as WPF Canvas, but there is problem
-
Saturday, April 07, 2012 1:36 PM
Hello
As i am still learning to work with Kinect in C#, i started the programming with rendering a video from Kinect, the added the code of depth image to be displayed, thus far everything works fine, the videos are displayed in image of Xaml code. Now i wanted to find a good way to display the joints "20 joins" each with its coordinate displayed. i wanted to use canvas, cause it looked straight forward in coding.
here is what i did :
public void SetEllipsePosition(Ellipse ellipse, Joint joint)
{
Canvas.SetLeft(ellipse, (320 * joint.Position.X) + 320);
Canvas.SetTop(ellipse, (240 * -joint.Position.Y) + 240);
}
void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
SkeletonData skeleton = (from p in e.SkeletonFrame.Skeletons
where p.TrackingState == SkeletonTrackingState.Tracked select p).FirstOrDefault();
SetEllipsePosition(HipCenter, skeleton.Joints[JointID.HipCenter]);
SetEllipsePosition(Spine, skeleton.Joints[JointID.Spine]);
SetEllipsePosition(ShoulderCenter, skeleton.Joints[JointID.ShoulderCenter]);
SetEllipsePosition(Head, skeleton.Joints[JointID.Head]);
SetEllipsePosition(ShoulderLeft, skeleton.Joints[JointID.ShoulderLeft]);
SetEllipsePosition(ElbowLeft, skeleton.Joints[JointID.ElbowLeft]);
SetEllipsePosition(WristLeft, skeleton.Joints[JointID.WristLeft]);
SetEllipsePosition(HandLeft, skeleton.Joints[JointID.HandLeft]);
SetEllipsePosition(ShoulderRight, skeleton.Joints[JointID.ShoulderRight]);
SetEllipsePosition(ElbowRight, skeleton.Joints[JointID.ElbowRight]);
SetEllipsePosition(WristRight, skeleton.Joints[JointID.WristRight]);
SetEllipsePosition(HandRight, skeleton.Joints[JointID.HandRight]);
SetEllipsePosition(HipLeft, skeleton.Joints[JointID.HipLeft]);
SetEllipsePosition(KneeLeft, skeleton.Joints[JointID.KneeLeft]);
SetEllipsePosition(AnkleLeft, skeleton.Joints[JointID.AnkleLeft]);
SetEllipsePosition(FootLeft, skeleton.Joints[JointID.FootLeft]);
SetEllipsePosition(HipRight, skeleton.Joints[JointID.HipRight]);
SetEllipsePosition(KneeRight, skeleton.Joints[JointID.KneeRight]);
SetEllipsePosition(AnkleRight, skeleton.Joints[JointID.AnkleRight]);
SetEllipsePosition(FootRight, skeleton.Joints[JointID.FootRight]);
}
and In xaml
<Grid Height="503" Width="792">
<Image Height="222" HorizontalAlignment="Left" Margin="12,12,0,0" Name="videoControl" Stretch="Fill" VerticalAlignment="Top" Width="295" />
<Button Content="Capture"
Height="25" HorizontalAlignment="Left"
Margin="88,466,0,0" Name="buttonCapture"
VerticalAlignment="Top" Width="104" Click="buttonCapture_Click" />
<Image Height="201" HorizontalAlignment="Left" Margin="12,249,0,0" Name="depthSourceControl" Stretch="Fill" VerticalAlignment="Top" Width="295" />
<Grid Margin="322,20,12,12">
<Canvas>
<Ellipse Height="10" Width="10" Fill="Blue" Name="HipCenter"/>
<Ellipse Height="10" Width="10" Fill="Blue" Name="Spine"/>
<Ellipse Height="10" Width="10" Fill="Blue" Name="ShoulderCenter"/>
<Ellipse Height="25" Width="15" Fill="yellow" Name="Head"/>
<Ellipse Height="10" Width="10" Fill="Blue" Name="ShoulderLeft"/>
<Ellipse Height="10" Width="10" Fill="Magenta" Name="ElbowLeft"/>
<Ellipse Height="10" Width="10" Fill="Blue" Name="WristLeft"/>
<Ellipse Height="10" Width="10" Fill="Blue" Name="HandLeft"/>
<Ellipse Height="10" Width="10" Fill="Blue" Name="ShoulderRight"/>
<Ellipse Height="10" Width="10" Fill="Magenta" Name="ElbowRight"/>
<Ellipse Height="10" Width="10" Fill="Blue" Name="WristRight"/>
<Ellipse Height="10" Width="10" Fill="Blue" Name="HandRight"/>
<Ellipse Height="10" Width="10" Fill="Blue" Name="HipLeft"/>
<Ellipse Height="15" Width="10" Fill="Red" Name="KneeLeft"/>
<Ellipse Height="10" Width="10" Fill="Blue" Name="AnkleLeft"/>
<Ellipse Height="10" Width="10" Fill="Blue" Name="FootLeft"/>
<Ellipse Height="10" Width="10" Fill="Blue" Name="HipRight"/>
<Ellipse Height="15" Width="10" Fill="Red" Name="KneeRight"/>
<Ellipse Height="10" Width="10" Fill="Blue" Name="AnkleRight"/>
<Ellipse Height="10" Width="10" Fill="Blue" Name="FootRight"/>
</Canvas>
</Grid>
</Grid>
</Window>
this gives a problem....without any errors
the issue is of the likes
also if i can address the problem of displaying the coordinates just near the joint points as (x,y,z) i am not sure if i can do that or not...
thank you
All Replies
-
Sunday, April 08, 2012 8:13 AM
Are you using beta sdk ?
If not you should use JointType not JointID. tha may help
-
Sunday, April 08, 2012 8:13 AM
HipCenter is null you must make sure that the joint is not null so you must initiate firstThanks,
MOHAMED A. SAKR | Software Development Lead Engineer | EgyptNetwork
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread. Also try to Vote as Helpful- Proposed As Answer by MohamedSakr Sunday, April 08, 2012 11:02 AM
-
Sunday, April 08, 2012 8:15 AM
Hello,
FirstOrDefault() will return null, when no skeleton is tracked. You need to check, if you have at least one tracked skeleton.
SkeletonData skeleton = e.SkeletonFrame.Skeletons.FirstOrDefault(p => p.TrackingState == SkeletonTrackingState.Tracked); if (skeleton != null) {
SetEllipsePosition(...)
... }
Best regards,
Thomas
- Proposed As Answer by Mauro Giusti [msft]Microsoft Employee Tuesday, April 10, 2012 4:53 AM
- Marked As Answer by Carmine Si - MSFTMicrosoft Employee, Owner Tuesday, May 01, 2012 10:01 PM
-
Wednesday, April 11, 2012 10:16 AM
thank you very much...
i wanted to also ask if possible, is there an inverse kinematics method that has been implemented. If not available in C#, how can i add C++ inverse kinematic algorithm in C# as a library.
I appreciate the help
-
Wednesday, April 11, 2012 1:39 PM
where do i intiate and with what ? what i idd initially is create a method
public bool IsSkeletalViewerAvailable
{
get { return KinectNui.Runtime.Kinects.All(k => k.SkeletonEngine == null); }
}then
i called it as follow
void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
SkeletonFrame skeletonFrame = e.SkeletonFrame;
if (IsSkeletalViewerAvailable == true )
{
foreach (SkeletonData skeleton in skeletonFrame.Skeletons)
{
if (SkeletonTrackingState.Tracked == skeleton.TrackingState)
{
JointID joint1 = JointID.HipCenter;
JointID joint2 = JointID.Spine;
JointID joint3 = JointID.ShoulderCenter;: :
that's what i did...but i get that problem box as shown above....
thanks Mohammed
-
Wednesday, April 11, 2012 2:50 PM
Try thisprivate void SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { using (SkeletonFrame frame = e.OpenSkeletonFrame()) { if (frame == null || frame.SkeletonArrayLength == 0) return; Skeleton[] skeletons = new Skeleton[frame.SkeletonArrayLength]; frame.CopySkeletonDataTo(skeletons); foreach (SkeletonData skeleton in skeletons) { if (skeleton != null) { if (skeleton.TrackingState == SkeletonTrackingState.Tracked) { //Kinect for Windows SDK SetEllipsePosition(HipCenter, skeleton.Joints[JointType.HipCenter]); //Kinect for xBox SDK SetEllipsePosition(HipCenter, skeleton.Joints[JointID.HipCenter]); } } } } }Thanks,
MOHAMED A. SAKR | Software Development Lead Engineer | EgyptNetwork
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread. Also try to Vote as Helpful- Proposed As Answer by MohamedSakr Wednesday, April 11, 2012 2:50 PM
-
Saturday, April 14, 2012 5:34 PMAny updates
Thanks,
MOHAMED A. SAKR | Software Development Lead Engineer | EgyptNetwork
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread. Also try to Vote as Helpful

