void Start() { Debug.Log ("Start(): Initializing nodes."); this.context = new Context (SAMPLE_XML_FILE); this.depth = context.FindExistingNode (NodeType.Depth) as DepthGenerator; if (this.depth == null) { Debug.LogError ("Viewer must have a depth node!"); } this.hands = context.FindExistingNode (NodeType.Hands) as HandsGenerator; if (this.hands == null) { Debug.LogError ("Viewer must have a hands node!"); } this.gestures = context.FindExistingNode (NodeType.Gesture) as GestureGenerator; if (this.gestures == null) { Debug.LogError ("Viewer must have a gestures node!"); } this.hands.HandCreate += new HandsGenerator.HandCreateHandler (hands_HandCreate); this.hands.HandUpdate += new HandsGenerator.HandUpdateHandler (hands_HandUpdate); this.hands.HandDestroy += new HandsGenerator.HandDestroyHandler (hands_HandDestroy); this.gestures.AddGesture ("Wave"); this.gestures.AddGesture ("RaiseHand"); this.gestures.GestureRecognized += new GestureGenerator.GestureRecognizedHandler (gestures_GestureRecognized); this.gestures.StartGenerating (); }
internal void Init(OpenNIManager manager) { _manager = manager; _handsGenerator = _manager.ONIContext.FindExistingNode(NodeType.Hands) as HandsGenerator; _handsGenerator.HandCreate += new HandsGenerator.HandCreateHandler(_handGenerator_HandCreate); _handsGenerator.HandDestroy += new HandsGenerator.HandDestroyHandler(_handGenerator_HandDestroy); _handsGenerator.HandUpdate += new HandsGenerator.HandUpdateHandler(_handGenerator_HandUpdate); _handsGenerator.GenerationRunningChanged += new StateChangedHandler(_handsGenerator_GenerationRunningChanged); _handsGenerator.StartGenerating(); }
/// <summary> /// Destructor /// </summary> public void Dispose() { File.Delete(this._xmlFileName); if (this._hands != null) { this._hands.Dispose(); this._hands = null; } if (this._gesture != null) { this._gesture.Dispose(); this._gesture = null; } this._context.Dispose(); this._context = null; }
/// <summary> /// Constructor /// </summary> public KinectWrap(KinectWrapProperties properties) { string xml; if (properties == null) { throw new Exception("KinectWrapProperties not provided"); } if (properties.HasGestureRecognition && properties.Gestures == null) { throw new Exception("KinectWrapProperties Gestures must at least have 1 gesture"); } this._resources = new ResourceManager(typeof(XmlFiles)); xml = this._resources.GetString("openniconfig"); this._xmlFileName = Guid.NewGuid().ToString().Replace("{", "").Replace("}", "").Replace("-", "") + ".xml"; this._xmlFileName = System.Reflection.Assembly.GetExecutingAssembly().Location + this._xmlFileName; using (StreamWriter wr = new StreamWriter(this._xmlFileName)) { wr.Write(xml); } this._context = new OpenNI.Context(this._xmlFileName); if (properties.HasHandTracking) { this._hands = new OpenNI.HandsGenerator(this._context); this._hands.HandUpdate += new OpenNI.HandsGenerator.HandUpdateHandler( delegate(OpenNI.ProductionNode node, uint id, ref OpenNI.Point3D position, float fTime) { if (properties.HandTrackHandler != null) { properties.HandTrackHandler.Invoke(new Point3D() { X = position.X, Y = position.Y, Z = position.Z }); } }); if (!properties.HasGestureRecognition) { this._hands.HandCreate += new OpenNI.HandsGenerator.HandCreateHandler( delegate(OpenNI.ProductionNode node, uint id, ref OpenNI.Point3D position, float fTime) { this._hands.StartTracking(ref position); }); } } if (properties.HasGestureRecognition) { this._gesture = new OpenNI.GestureGenerator(this._context); foreach (GestureType g in properties.Gestures) { switch (g) { case GestureType.Wave: { this._gesture.AddGesture("Wave"); break; } default: { break; } } } this._gesture.GestureRecognized += new OpenNI.GestureGenerator.GestureRecognizedHandler( delegate(OpenNI.ProductionNode node, string strGesture, ref OpenNI.Point3D idPosition, ref OpenNI.Point3D endPosition) { if (properties.GestureHandler != null) { GestureType gt; switch (strGesture) { case "Wave": { gt = GestureType.Wave; break; } default: { gt = GestureType.Wave; break; } } properties.GestureHandler.Invoke(gt, new Point3D() { X = endPosition.X, Y = endPosition.Y, Z = endPosition.Z }); } if (properties.HasHandTracking) { this._hands.StartTracking(ref endPosition); } }); } if (properties.HasHandTracking) { this._hands.StartGenerating(); } if (properties.HasGestureRecognition) { this._gesture.StartGenerating(); } System.Threading.Thread th = new System.Threading.Thread(delegate() { try { while (true) { this._context.WaitAnyUpdateAll(); } } finally { this.Dispose(); } }); th.Start(); }