public MainPage() { this.kinectSensor = KinectSensor.GetDefault(); this.coordinateMapper = this.kinectSensor.CoordinateMapper; this.multiSourceFrameReader = this.kinectSensor.OpenMultiSourceFrameReader(FrameSourceTypes.Infrared | FrameSourceTypes.Color | FrameSourceTypes.Depth | FrameSourceTypes.BodyIndex | FrameSourceTypes.Body); this.multiSourceFrameReader.MultiSourceFrameArrived += this.Reader_MultiSourceFrameArrived; // get the infraredFrameDescription from the InfraredFrameSource // FrameDescription infraredFrameDescription = this.kinectSensor.InfraredFrameSource.FrameDescription; // reader for infrared frames // this.infraredFrameReader = this.kinectSensor.InfraredFrameSource.OpenReader(); // event handler for frame arrival // this.infraredFrameReader.FrameArrived += this.Reader_InfraredFrameArrived; // intermediate storage for receiving frame data from the sensor //this.infraredFrameData = // new ushort[infraredFrameDescription.Width * infraredFrameDescription.Height]; //// intermediate storage for frame data converted to color pixels for display //this.infraredPixels = // new byte[infraredFrameDescription.Width * infraredFrameDescription.Height * BytesPerPixel]; //// create the bitmap to display, which will replace the contents of an image in XAML //this.bitmap = // new WriteableBitmap(infraredFrameDescription.Width, infraredFrameDescription.Height); // open the sensor this.kinectSensor.Open(); this.InitializeComponent(); this.Loaded += MainPage_Loaded; //lab 13 // Initialize the gesture detection objects for our gestures this.gestureDetectorList = new List <GestureDetector>(); //lab 13 // Create a gesture detector for each body (6 bodies => 6 detectors) int maxBodies = 6; // this.kinectSensor.BodyFrameSource.BodyCount; for (int i = 0; i < maxBodies; ++i) { GestureResultView result = new GestureResultView(i, false, false, 0.0f); GestureDetector detector = new GestureDetector(this.kinectSensor, result); result.PropertyChanged += GestureResult_PropertyChanged; this.gestureDetectorList.Add(detector); } }
/// <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 // 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.seatedGestureName)) // { // this.vgbFrameSource.AddGesture(gesture); // } //} // load all available gestures in the database // this.vgbFrameSource.AddGestures(database.AvailableGestures); //} using (VisualGestureBuilderDatabase database = new VisualGestureBuilderDatabase(this.gestureDatabase)) { foreach (Gesture gesture in database.AvailableGestures) { System.Diagnostics.Debug.WriteLine("GESTURE!"); } this.vgbFrameSource.AddGestures(database.AvailableGestures); } }
void GestureResult_PropertyChanged(object sender, PropertyChangedEventArgs e) { GestureResultView result = sender as GestureResultView; if (result.Confidence > 0.1) { this.GestureName.Text = result.GestureName; if (result.GestureName == "Squat") { this.isSquat = true; } } else { this.GestureName.Text = "Not Squat"; this.isSquat = false; } //this.GestureConfidence.Text = result.Confidence.ToString(); }