/// <summary> /// Creates a new Gestures Handler /// </summary> /// <param name="manager">The manager that controls the handler</param> internal KinectGestureTracker(OpenNIManager manager) { //Assign the manager _manager = manager; manager.Deactivated += new EventHandler<EventArgs>(manager_Deactivated); //Add the wave recognizer as this will start a session. //_startSessionGenerator = manager.ONIContext.FindExistingNode(NodeType.Gesture) as GestureGenerator; _startSessionGenerator = new GestureGenerator(manager.ONIContext); _startSessionGenerator.AddGesture("Wave"); _startSessionGenerator.AddGesture("Click"); _startSessionGenerator.GestureRecognized += new GestureGenerator.GestureRecognizedHandler(_startSessionGenerator_GestureRecognized); _startSessionGenerator.GestureChanged += new StateChangedHandler(_startSessionGenerator_GestureChanged); _startSessionGenerator.GestureProgress += new GestureGenerator.GestureProgressHandler(_startSessionGenerator_GestureProgress); _startSessionGenerator.GenerationRunningChanged += new StateChangedHandler(_startSessionGenerator_GenerationRunningChanged); _startSessionGenerator.NewDataAvailable += new StateChangedHandler(_startSessionGenerator_NewDataAvailable); //The gesture generator will detect gestures after the session has been activated. _gestureGenerator = new GestureGenerator(manager.ONIContext); _gestureGenerator.GestureRecognized += new GestureGenerator.GestureRecognizedHandler(_gestureGenerator_GestureRecognized); _gestureGenerator.GestureChanged += new StateChangedHandler(_gestureGenerator_GestureChanged); _gestureGenerator.GestureProgress += new GestureGenerator.GestureProgressHandler(_gestureGenerator_GestureProgress); _gestureGenerator.GenerationRunningChanged += new StateChangedHandler(_gestureGenerator_GenerationRunningChanged); _gestureGenerator.NewDataAvailable += new StateChangedHandler(_gestureGenerator_NewDataAvailable); _handGestures = new List<HandGesture>(); }
private void Track(AsyncStateData asyncData) { asyncData.Running = true; InitOpenNi(asyncData); while (!asyncData.Canceled) { try { _niContext.WaitAndUpdateAll(); // update image metadata _imageNode.GetMetaData(_imageMeta); _depthNode.GetMetaData(_depthMeta); //_sceneNode..GetMetaData(_sceneMeta); GestureGenerator gg = new GestureGenerator(_niContext); gg.AddGesture("Wave"); gg.GestureRecognized += new GestureGenerator.GestureRecognizedHandler(gg_GestureRecognized); gg.StartGenerating(); _depthHist.Update(_depthMeta); // _sceneMap.Update(_sceneMeta); // continue update on UI thread asyncData.AsyncOperation.SynchronizationContext.Send( delegate { // Must be called on the synchronization thread. CopyWritableBitmap(_imageMeta, _rgbImageSource); // CopyWritableBitmap(_depthMeta, _depthImageSource); _depthHist.Paint(_depthMeta, _depthImageSource); //CopyWritableBitmap(_sceneMeta, _sceneImageSource); //_sceneMap.Paint(_sceneMeta, _sceneImageSource); InvokeUpdateViewPort(EventArgs.Empty); }, null); } catch(Exception ex) { System.Diagnostics.Debug.WriteLine("An error has occured in Track: " + ex.Message); } } asyncData.Running = false; asyncData.AsyncOperation.PostOperationCompleted(evt => InvokeTrackinkgCompleted(EventArgs.Empty), null); }