/// <summary> /// Starts the skeleton reading process and sends the colour image to be used for skeleton mapping /// </summary> private void InitiateSkel(KinectSensor newSensor) { //Create SkeltonLib Obj with active sensor skelObj = new SkeletonLib(newSensor); skelObj.SkeletonStart(); skelObj.setColourImage(this.streamImg); //Tie image source to output of object this.Image.Source = skelObj.getOutputImage(); // Add an event handler to be called whenever there is new skeleton frame data newSensor.SkeletonFrameReady += skelObj.SensorSkeletonFrameReady; }
/// <summary> /// Handle the background removed color frame ready event. The frame obtained from the background removed /// color stream is in RGBA format. /// </summary> /// <param name="sender">object that sends the event</param> /// <param name="e">argument of the event</param> private void BackgroundRemovedFrameReadyHandler(object sender, BackgroundRemovedColorFrameReadyEventArgs e) { using (var backgroundRemovedFrame = e.OpenBackgroundRemovedColorFrame()) { if (backgroundRemovedFrame != null) { if (null == this.foregroundBitmap || this.foregroundBitmap.PixelWidth != backgroundRemovedFrame.Width || this.foregroundBitmap.PixelHeight != backgroundRemovedFrame.Height) { this.foregroundBitmap = new WriteableBitmap(backgroundRemovedFrame.Width, backgroundRemovedFrame.Height, 96.0, 96.0, PixelFormats.Bgra32, null); } // Write the pixel data into our bitmap this.foregroundBitmap.WritePixels( new Int32Rect(0, 0, this.foregroundBitmap.PixelWidth, this.foregroundBitmap.PixelHeight), backgroundRemovedFrame.GetRawPixelData(), this.foregroundBitmap.PixelWidth * sizeof(int), 0); // Set the image we display to point to the bitmap where we'll put the image data //this.Image.Source = this.foregroundBitmap; if (skelObj.isEmpty() == false) { skelObj.SkeletonStart(this.foregroundBitmap, this.sensorChooser.Kinect); // Set the image we display to point to the bitmap where we'll put the image data this.Image.Source = skelObj.getOutputImage(); } else { // Set the image we display to point to the bitmap where we'll put the image data this.Image.Source = this.foregroundBitmap; } } } }