title: Gesture recognition using OpenNI, NiTE, C#, Xtion Pro Live device
body: <p>In my app, using input from an ASUS Xtion Pro Live device, I'd like to leverage NiTE for gesture recognition, because my own gesture recognition code, based on the skeleton capability of OpenNI, is clunky and not entirely reliable.</p>
  
  <p>I'm using the OpenNI.net.dll v1.5.2.23 and XnVNITE.net.dll v1.5.2.21, this is what came on the CD with the device. Seems they didn't make .NET wrappers for v2 anyway.</p>
  
  <p>Just to get off the ground, I wrote some code based on the NiHandViewer/HandViewer.java samples, but it doesn't do anything, no events are fired and I haven't been able to find any useful NiTE C# samples to point me in the right direction.</p>
  
  <p>What is wrong with the code below?</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using OpenNI;
  using NITE;
  using System.Threading.Tasks;
  
  namespace NiTEPlayground
  {
      static class Point3DExtensions
      {
          public static string ToTripletString(this Point3D point3d)
          {
              return String.Format("({0}, {1}, {2})", point3d.X, point3d.Y, point3d.Z);
          }
      }
  
      class Program
      {
          static Context context;
          static GestureGenerator generator;
          static HandsGenerator handsGen;
  
          static void Main(string[] args)
          {
              ScriptNode scriptNode;
              context = Context.CreateFromXmlFile("SamplesConfig.xml", out scriptNode);
  
              generator = new GestureGenerator(context);
              generator.AddGesture("Wave");
              generator.AddGesture("Click");
              generator.GestureRecognized += new EventHandler&lt;GestureRecognizedEventArgs&gt;(generator_GestureRecognized);
              generator.GestureProgress += new EventHandler&lt;GestureProgressEventArgs&gt;(generator_GestureProgress);
  
              handsGen = new HandsGenerator(context);
              handsGen.HandCreate += new EventHandler&lt;HandCreateEventArgs&gt;(handsGen_HandCreate);
              handsGen.HandUpdate += new EventHandler&lt;HandUpdateEventArgs&gt;(handsGen_HandUpdate);
              handsGen.HandDestroy += new EventHandler&lt;HandDestroyEventArgs&gt;(handsGen_HandDestroy);
  
              context.StartGeneratingAll();
  
              Task.Factory.StartNew(() =&gt;
              {
                  while (true)
                  {
                      context.WaitAnyUpdateAll();
                  }
              });
  
              Console.ReadKey();
          }
  
          static void generator_GestureProgress(object sender, GestureProgressEventArgs e)
          {
              Console.WriteLine("Gesture Progress: {0}; {1}; {2}", e.Gesture, e.Position.ToTripletString(), e.Progress);
          }
  
          static void handsGen_HandDestroy(object sender, HandDestroyEventArgs e)
          {
              Console.WriteLine("Hand Create: {0}, {1}", e.UserID, e.Time);
          }
  
          static void handsGen_HandUpdate(object sender, HandUpdateEventArgs e)
          {
              Console.WriteLine("Hand Update: {0}, {1}, {2}", e.UserID, e.Time, e.Position.ToTripletString());
          }
  
          static void handsGen_HandCreate(object sender, HandCreateEventArgs e)
          {
              Console.WriteLine("Hand Create: {0}, {1}, {2}", e.UserID, e.Time, e.Position.ToTripletString());
          }
  
          static void generator_GestureRecognized(object sender, GestureRecognizedEventArgs e)
          {
              Console.WriteLine("Gesture:{0}; Identified:{1}; End:{2}", e.Gesture, e.IdentifiedPosition.ToTripletString(), e.EndPosition.ToTripletString());
          }
      }
  }
  </code></pre>