3

I was hoping someone could help point me in the right direction.

I'm looking for a way to use the Microsoft Kinect to turn off a lamp. The lamp is connected to a Home Easy remote socket switch which is paired with a Telldus Tellstick. I am using C# to write the application, now I have a vague idea in my head what I would like to do, and after using the Kinect SDK I have a better understanding of how to use the Kinect.

What I would like to know is what would be the most logical way to create this application? I was thinking something along the lines of: Initialize Kinect > When Kinect ready then scan for skeleton > when skeleton detected, mark boolean value as 'true' > when value true, turn light on.

I know that is very vague, but I am new to developing with the kinect and overall my I'm still learning C#. Any help, no matter how small would be greatly appreciated!

Regards, John.

J.Doe
  • 33
  • 6
  • Initialize Kinect > When Kinect ready then scan for skeleton > when skeleton detected, mark boolean value as 'true' its more logical way – Mustafa Ekici Apr 06 '12 at 15:19
  • Thanks Mekici, I was curious to know whether or not I would have to collect any data from the skeletal tracking or if i can just specify the boolean command without any further issues? – J.Doe Apr 06 '12 at 16:32
  • Infact skeleton tracking doesnt necessary! why you have to use skeleton processing? your approach can be simple image processing which is Motion Detection? – Mustafa Ekici Apr 06 '12 at 16:47
  • I would like to be able to show Live skeletal data whilst the application is running just to enhance the GUI. – J.Doe Apr 06 '12 at 21:19
  • I don't know if this is true in the SDK, but in the beta versions whenever i used a bool to tell if someone was detected everything froze. I would guess they fixed that(I hope) – Liam McInroy Apr 07 '12 at 02:50

1 Answers1

1

You can't set a simple boolean for this because the SDK's event driven approach will return 6 skeletal structures even if they are all empty. Using a bit of LINQ and a null check will get you what you are looking for though.

Steps:

  1. Initialize Kinect (I would use the included KinectSensorChooser for this app WPFViewers) enable and register for the skeletal stream.
  2. In the skeletal event check to make sure you didn't get a null skeleton collection (it happens)
  3. Use LINQ to get the first skeleton that has it's tracking property set to tracked. You can also just use a for loop, I just find LINQ to be useful for these types of iteration.
  4. If your skeleton after the LINQ query is not null do something.

If you are wanting to get this up quick and with some flair you can utilize the sample that is included when you download the SDK Kinect Explorer. There is a skeletal viewer along with KinectSensorChooser that will allow you to have a fully functioning app with very little code. read more about the Skeletal Viewer included with this sample here


I stumbled a little bit with wether to provide code for this or not. I thought it better to answer this with the logic needed to perform the action rather than the actual code... since you asked :) however, if you want code for this you can either get it from Channel 9's Quickstarts or my book chapter four


Edit (Extending KinectExplorer):

In order to extend KinectExplorer to respond when a skeleton is detected just find the function KinectAllFramesReady in KinectSkeletonViewer.xaml.cs. Inside of this function there is a bool check for haveSkeletonData, this if statement will get called when there is a skeleton present in the viewable frame of the Kinect. so:

   private void KinectAllFramesReady(object sender, AllFramesReadyEventArgs e)
   {
    //Checking for Skeleton
    if (haveSkeletonData)
    {
     //Do Stuff Here
    }
   }
davidbates
  • 1,792
  • 1
  • 10
  • 14
  • Hi David, Thanks for your response. Just as a side note, I was planning to buy your book at the beginning of the year! But the launch date was a little to late for myself. I have got as far as using the WPF viewer for the colour stream and it is registered for a Skeletal scheme. I don't understand the Skeletal SDK example though, as my knowledge on C# is still very limited. The quick start guides help but don't really target what I'm looking to do. Would it be possible for you to just provide some code to point me in the right direction? it doesn't have to be thorough... – J.Doe Apr 13 '12 at 17:30
  • 1
    Thanks J.Doe, My book was set back because of the vast amount of changes in the API on release of V1. I wanted to make sure anyone picking it up could just use the latest version... I made an edit to my answer to give you pointers on where to look in KinectExplorer to inject your code. I hope that helps. – davidbates Apr 15 '12 at 04:54
  • Also `int`s seem to work, eg. `int PersonDetected = 0; Skeleton skeleton; if (skeleton.TrackingState == SkeletonTrackingState.Tracked) { PersonDetected = 1; }` – Liam McInroy Apr 22 '12 at 02:35
  • I have tried your suggestion Outlaw Lemur, but i keep getting the error message use of unassigned local variable and i just can't seem to work out what it means! – J.Doe Apr 25 '12 at 18:48
  • @J.Doe that is because `skeleton` is not yet defined.... see http://stackoverflow.com/questions/10451456/kinect-skeletal-tracking-not-working – Liam McInroy May 18 '12 at 13:27
  • @davidbates Cool book! Ordering one soon;) – Liam McInroy May 18 '12 at 13:31