public MainWindow() { lce = new LifeCycleEvents("TOUCH", "FUSION", "touch-1", "touch", "command"); mmic = new MmiCommunication("localhost", 9876, "User1", "TOUCH"); mmic.Send(lce.NewContextRequest()); InitializeComponent(); // only one sensor is currently supported this.kinectSensor = KinectSensor.GetDefault(); // open the sensor this.kinectSensor.Open(); // set the initial status text this.UpdateKinectStatusText(); // open the reader for the body frames this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader(); // initialize the BodyViewer object for displaying tracked bodies in the UI this.kinectBodyView = new KinectBodyView(this.kinectSensor); // initialize the GestureDetector object this.gestureResultView = new GestureResultView(false, 0, 0); this.gestureDetector = new GestureDetector(this.kinectSensor, this.gestureResultView); // set data context objects for display in UI this.DataContext = this; this.kinectBodyViewbox.DataContext = this.kinectBodyView; //this.gestureResultGrid.DataContext = this.gestureResultView; }
/// <summary> /// Initializes a new instance of the GestureDetector class along with the gesture frame source and reader /// </summary> /// <param name="kinectSensor">Active sensor to initialize the VisualGestureBuilderFrameSource object with</param> /// <param name="gestureResultView">GestureResultView object to store gesture results of a single body to</param> public GestureDetector(KinectSensor kinectSensor, GestureResultView gestureResultView) { if (kinectSensor == null) { throw new ArgumentNullException("kinectSensor"); } if (gestureResultView == null) { throw new ArgumentNullException("gestureResultView"); } this.GestureResultView = gestureResultView; //this.ClosedHandState = false; // create the vgb source. The associated body tracking ID will be set when a valid body frame arrives from the sensor. this.vgbFrameSource = new VisualGestureBuilderFrameSource(kinectSensor, 0); // open the reader for the vgb frames this.vgbFrameReader = this.vgbFrameSource.OpenReader(); if (this.vgbFrameReader != null) { this.vgbFrameReader.IsPaused = true; } // load all gestures from the gesture database using (var database = new VisualGestureBuilderDatabase(this.gestureDatabase)) { this.vgbFrameSource.AddGestures(database.AvailableGestures); } // disable the set of gestures which determine the 'keep straight' behavior, we will use hand state instead /* foreach (var gesture in this.vgbFrameSource.Gestures) * { * if (gesture.Name.Equals(this.Kill_gesture) || gesture.Name.Equals(this.Pray_gesture)) * { * this.vgbFrameSource.SetIsEnabled(gesture, false); * } * }*/ }