/// <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="stadingResultView">GestureResultView object to store gesture results of a single body to</param> /// /// <param name="armsCrossedResultView">GestureResultView object to store gesture results of a single body to</param> public GestureDetector(KinectSensor kinectSensor, StandingResultView standingResultView, ArmsCrossedResultView armsCrossedResultView) { if (kinectSensor == null) { throw new ArgumentNullException("kinectSensor"); } if (standingResultView == null) { throw new ArgumentNullException("standingResultView"); } if (armsCrossedResultView == null) { throw new ArgumentNullException("armsCrossedResultView"); } this.StandingResultView = standingResultView; this.ArmsCrossedResultView = armsCrossedResultView; // 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); this.vgbFrameSource.TrackingIdLost += this.Source_TrackingIdLost; // open the reader for the vgb frames this.vgbFrameReader = this.vgbFrameSource.OpenReader(); if (this.vgbFrameReader != null) { this.vgbFrameReader.IsPaused = true; this.vgbFrameReader.FrameArrived += this.Reader_GestureFrameArrived; } // load the 'Seated' gesture from the gesture database using (VisualGestureBuilderDatabase database = new VisualGestureBuilderDatabase(this.gestureDatabase)) { //Need WORK try { this.vgbFrameSource.AddGestures(database.AvailableGestures); } catch { } } }
// Creates Timer /// <summary> /// Initializes a new instance of the MainWindow class /// </summary> public FeedbackDisplay() { // only one sensor is currently supported this.kinectSensor = KinectSensor.GetDefault(); // set IsAvailableChanged event notifier this.kinectSensor.IsAvailableChanged += this.Sensor_IsAvailableChanged; // open the sensor this.kinectSensor.Open(); // set the status text this.StatusText = this.kinectSensor.IsAvailable ? Properties.Resources.RunningStatusText : Properties.Resources.NoSensorStatusText; // open the reader for the body frames this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader(); // set the BodyFramedArrived event notifier this.bodyFrameReader.FrameArrived += this.Reader_BodyFrameArrived; // initialize the BodyViewer object for displaying tracked bodies in the UI this.kinectBodyView = new KinectBodyView(this.kinectSensor); // initialize the gesture detection objects for our gestures this.gestureDetectorList = new List <GestureDetector>(); // initialize the MainWindow this.InitializeComponent(); // set our data context objects for display in UI this.DataContext = this; this.kinectBodyViewbox.DataContext = this.kinectBodyView; // create a gesture detector for each body (6 bodies => 6 detectors) and create content controls to display results in the UI int col0Row = 0; int col1Row = 0; //int maxBodies = this.kinectSensor.BodyFrameSource.BodyCount; int maxBodies = 1; for (int i = 0; i < maxBodies; ++i) { StandingResultView standingResult = new StandingResultView(0, false, false, 0.0f); ArmsCrossedResultView armsCrossedResult = new ArmsCrossedResultView(0, false, false, 0.0f); GestureDetector detector = new GestureDetector(this.kinectSensor, standingResult, armsCrossedResult); this.gestureDetectorList.Add(detector); // split gesture results across the first two columns of the content grid ContentControl standingcontentControl = new ContentControl(); ContentControl armscrossedcontentControl = new ContentControl(); standingcontentControl.Content = this.gestureDetectorList[i].StandingResultView; armscrossedcontentControl.Content = this.gestureDetectorList[i].ArmsCrossedResultView; if (i % 2 == 0) { // Gesture results for bodies: 0, 2, 4 Grid.SetColumn(standingcontentControl, 0); Grid.SetColumn(armscrossedcontentControl, 0); Grid.SetRow(standingcontentControl, col0Row); Grid.SetRow(armscrossedcontentControl, col0Row + 1); ++col0Row; } else { // Gesture results for bodies: 1, 3, 5 Grid.SetColumn(standingcontentControl, 0); Grid.SetColumn(armscrossedcontentControl, 0); Grid.SetRow(standingcontentControl, col1Row); Grid.SetRow(armscrossedcontentControl, col1Row + 1); ++col1Row; } this.contentGrid.Children.Add(standingcontentControl); this.contentGrid.Children.Add(armscrossedcontentControl); } }