/// <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; // 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)) { // we could load all available gestures in the database with a call to vgbFrameSource.AddGestures(database.AvailableGestures), // but for this program, we only want to track one discrete gesture from the database, so we'll load it by name foreach (Gesture gesture in database.AvailableGestures) { if (gesture.Name.Equals(this.SlideRight)) { this.vgbFrameSource.AddGesture(gesture); } if (gesture.Name.Equals(this.SlideRightProgress)) { this.vgbFrameSource.AddGesture(gesture); } if (gesture.Name.Equals(this.SlideLeft)) { this.vgbFrameSource.AddGesture(gesture); } if (gesture.Name.Equals(this.SlideLeftProgress)) { this.vgbFrameSource.AddGesture(gesture); } } } }
public MainWindow() { // get Active Kinect Sensor this.sensor = KinectSensor.GetDefault(); // open the sensor this.sensor.Open(); this.DataContext = this.viewModel; this.viewModel.TrainName = "Face 1"; this.viewModel.ProcessorType = ProcessorTypes.PCA; this.viewModel.PropertyChanged += this.ViewModelPropertyChanged; this.viewModel.TrainButtonClicked = new ActionCommand(this.Train); this.viewModel.TrainNameEnabled = true; // open the reader for the body frames this.bodyFrameReader = sensor.BodyFrameSource.OpenReader(); this.bodyFrameReader.FrameArrived += bodyFrameReader_FrameArrived; // initialize the gesture detection objects for our gestures this.gestureDetectorList = new List <GestureDetector>(); //this.InitializeComponent(); this.LoadProcessor(); // get screen with and height screenWidth = (int)SystemParameters.PrimaryScreenWidth; screenHeight = (int)SystemParameters.PrimaryScreenHeight; // set up timer, execute every 0.1s timer.Interval = new TimeSpan(0, 0, 0, 0, 100); timer.Tick += new EventHandler(Timer_Tick); timer.Start(); int maxBodies = this.sensor.BodyFrameSource.BodyCount; for (int i = 0; i < maxBodies; ++i) { GestureResultView result = new GestureResultView(false, false, 0.0f, -1.0f, false, false, false); GestureDetector detector = new GestureDetector(this.sensor, result); this.gestureDetectorList.Add(detector); } }