/// <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); // Set the image we display to point to the bitmap where we'll put the image data //this.MaskedColor.Source = this.foregroundBitmap; this.MaskedColor.ImageSource = this.foregroundBitmap; } // 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); } } }
/// <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) { Array.Copy(backgroundRemovedFrame.GetRawPixelData(), GB.BackgroundRemovedBuffer, GB.BackgroundRemovedBuffer.Length); } } Draw(); }
void backgroundstream_BackgroundRemovedFrameReady(object sender, BackgroundRemovedColorFrameReadyEventArgs e) { using (var backgroundRemovedFrame = e.OpenBackgroundRemovedColorFrame()) { if (backgroundRemovedFrame != null) { lock (m_lock) { backgroundRemovedFrame.CopyPixelDataTo(this.bgdata); } } } }
/// <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); // Set the image we display to point to the bitmap where we'll put the image data this.MaskedColor.Source = this.foregroundBitmap; } byte[] pixelData = new byte[backgroundRemovedFrame.PixelDataLength]; backgroundRemovedFrame.CopyPixelDataTo(pixelData); for (int i = 0; i < pixelData.Length; i += BackgroundRemovedColorFrame.BytesPerPixel) { pixelData[i] = 0; pixelData[i + 1] = 102; pixelData[i + 2] = 0; } if (!pictureTaken) { // Write the pixel data into our bitmap this.foregroundBitmap.WritePixels( new Int32Rect(0, 0, this.foregroundBitmap.PixelWidth, this.foregroundBitmap.PixelHeight), pixelData, this.foregroundBitmap.PixelWidth * sizeof(int), 0); } else { if (speechInteraction.outlines) { if (!AlreadyConvertedToSVG) { GetSVGOutlinesString(); AlreadyConvertedToSVG = true; } } } } } }
/// <summary> /// Event handler for BackgroundRemovedColorStream's BackgroundRemovedFrameReady event /// </summary> /// <param name="sender">object sending the event</param> /// <param name="e">event arguments</param> internal async void BackgroundRemovedFrameReadyAsync(object sender, BackgroundRemovedColorFrameReadyEventArgs e) { if (!this.backgroundRemovalStreamIsEnabled) { // Directly return if the stream is not enabled. return; } if (this.isProcessingBackgroundRemovedFrame) { // Re-entered BackgroundRemovedFrameReadyAsync while a previous frame is already being processed. // Just ignore new frames until the current one finishes processing. return; } this.isProcessingBackgroundRemovedFrame = true; try { bool haveFrameData = false; using (var backgroundRemovedFrame = e.OpenBackgroundRemovedColorFrame()) { if (backgroundRemovedFrame != null) { this.backgroundRemovalStreamMessage.UpdateBackgroundRemovedColorFrame(backgroundRemovedFrame); haveFrameData = true; } } if (haveFrameData) { await this.ownerContext.SendTwoPartStreamMessageAsync(this.backgroundRemovalStreamMessage, this.backgroundRemovalStreamMessage.Buffer); } } finally { this.isProcessingBackgroundRemovedFrame = false; } }
/// <summary> /// Handle a new background-removed color frame. The frame obtained from the stream /// is in BGRA format. /// </summary> /// <param name="sender">Object sending the event.</param> /// <param name="e">Event arguments.</param> private void BackgroundRemovedFrameReadyHandler( object sender, BackgroundRemovedColorFrameReadyEventArgs e) { using (var backgroundRemovedFrame = e.OpenBackgroundRemovedColorFrame()) { if (null != backgroundRemovedFrame && this.IsTracked) { int width = backgroundRemovedFrame.Width; int height = backgroundRemovedFrame.Height; WriteableBitmap foregroundBitmap = this.imageControl.Source as WriteableBitmap; // If necessary, allocate new bitmap. Set it as the source of the Image control. if (null == foregroundBitmap || foregroundBitmap.PixelWidth != width || foregroundBitmap.PixelHeight != height) { foregroundBitmap = new WriteableBitmap( width, height, 96.0, 96.0, PixelFormats.Bgra32, null); this.imageControl.Source = foregroundBitmap; } // Write the pixel data into our bitmap. foregroundBitmap.WritePixels( new Int32Rect(0, 0, width, height), backgroundRemovedFrame.GetRawPixelData(), width * sizeof(uint), 0); // A frame has been delivered; ensure that it is visible. this.imageControl.Visibility = Visibility.Visible; } } }
/// <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> public 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); } this.imgSource = this.foregroundBitmap; // 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); } } }
/// <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; } } } }
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) { // WriteableBitmap bit = WriteableBitmap(Happy.Source); this.foregroundBitmap = new WriteableBitmap(backgroundRemovedFrame.Width, backgroundRemovedFrame.Height, 96.0, 96.0, PixelFormats.Bgra32, null); // Set the image we display to point to the bitmap where we'll put the image data this.MaskedColor.Source = this.foregroundBitmap; } if (original == 0) { original = image.Width; } if (stage == 0) { if (s != null && currentlyTrackedSkeletonId >= 0) { stage = 1; } } else if (stage == 1) { counter++; Matching.FontSize = 30; Matching.Text = "Initializing"; if (counter == 20) { stage = 2; counter = 0; } } else if (stage == 2) { counter++; Matching.FontSize = 60; Matching.Text = ((105 - counter) / 35 + 1).ToString(); if (counter == 105) { stage = 3; counter = 0; } } else if (stage == 3 || stage == 4) { if (stage == 3 && counter < 40) { counter++; Matching.FontSize = 60 - counter; Matching.Text = "Go"; if (counter == 40) { stage = 4; counter = 0; } } if (stage == 4) { image.Width = sizeIm; if (sizeIm < foregroundBitmap.PixelWidth + 100) { sizeIm += rate; var total = 0; if (s != null) { foreach (Joint joint in s.Joints) { ColorImagePoint point = ks.CoordinateMapper.MapSkeletonPointToColorPoint(joint.Position, ColorImageFormat.RgbResolution640x480Fps30); if (point.X > -1000000 && point.X < 1000000 && point.Y > -1000000 && point.Y < 1000000) { Joint j = joint; int pos = point.Y * stride + 4 * point.X; if (pos >= 0 && pos < sil.Length && sil[pos] == 255 && sil[pos + 1] == 255 && sil[pos + 2] == 255) { total += 1; } } } Matching.Text = "Matching: " + (total * 100 / s.Joints.Count).ToString() + "%"; } else { Matching.Text = "Matching: 0%"; } Matching.FontSize = 30; } else { stage = 5; savedBackground = backgroundRemovedFrame; savedForeground = foregroundBitmap; // UpdateImage("Images//Bent.png"); // image.Width = sizeIm; // image.UpdateLayout(); } } } else if (stage == 5) { counter++; GoodJob.Visibility = System.Windows.Visibility.Visible; if (image == Dog) { GoodJob.Text = "Woof! Bark!"; } else { GoodJob.Text = "Good Job"; } if (counter == 100) { stage = 6; counter = 0; GoodJob.Visibility = System.Windows.Visibility.Hidden; } // Happy.Visibility = System.Windows.Visibility.Hidden; // HappyEnd.Visibility = System.Windows.Visibility.Visible; // HappyEnd.Width = Happy.Width; // this.MaskedColor.Source = wb; // backgroundRemovedFrame = br; /* foreach (Joint joint in jc) { ColorImagePoint point = ks.CoordinateMapper.MapSkeletonPointToColorPoint(joint.Position, ColorImageFormat.RgbResolution640x480Fps30); if (point.X > -1000000 && point.X < 1000000 && point.Y > -1000000 && point.Y < 1000000) { Joint j = joint; int pos = point.Y * stride + 4 * point.X; if (pos >= 0 && pos < sil.Length && sil[pos] == 255 && sil[pos + 1] == 255 && sil[pos + 2] == 255) { // MaskedColor. } } }*/ } else if (stage == 6) { sizeIm -= 4; if (sizeIm > startingSize) { image.Width = sizeIm; } else { stage = 1; counter = 0; rate += 1; ResetGame(); } } if (savedBackground == 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); } else { // Write the pixel data into our bitmap /* this.foregroundBitmap.WritePixels( new Int32Rect(0, 0, this.savedForeground.PixelWidth, this.savedForeground.PixelHeight), savedBackground.GetRawPixelData(), this.savedForeground.PixelWidth * sizeof(int), 0);*/ } } } }
/// <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); // Set the image we display to point to the bitmap where we'll put the image data this.imgMaskedColor.Source = this.foregroundBitmap; } // 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); } } }
/// <summary> /// When the background removed frame is ready, create a Bitmap and add it to the UI /// </summary> public void BackgroundRemovedFrameReadyHandler(object sender, BackgroundRemovedColorFrameReadyEventArgs args) { using (var backgroundRemovedFrame = args.OpenBackgroundRemovedColorFrame()) { if (backgroundRemovedFrame != null) { if (null == foregroundBitmap || foregroundBitmap.PixelWidth != backgroundRemovedFrame.Width || foregroundBitmap.PixelHeight != backgroundRemovedFrame.Height) { foregroundBitmap = new WriteableBitmap(backgroundRemovedFrame.Width, backgroundRemovedFrame.Height, 96.0, 96.0, PixelFormats.Bgra32, null); // Set the image we display to point to the bitmap which contains the background removed image data MaskedColor.Source = foregroundBitmap; } // Write the pixel data into our bitmap foregroundBitmap.WritePixels( new Int32Rect(0, 0, foregroundBitmap.PixelWidth, foregroundBitmap.PixelHeight), backgroundRemovedFrame.GetRawPixelData(), foregroundBitmap.PixelWidth * sizeof(int), 0); } } }
/// <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.Width != backgroundRemovedFrame.Width || this.foregroundBitmap.Height != backgroundRemovedFrame.Height) { //this.foregroundBitmap = new WriteableBitmap(backgroundRemovedFrame.Width, backgroundRemovedFrame.Height, 96.0, 96.0, PixelFormats.Bgra32, null); this.foregroundBitmap = new Texture2D(graphics.GraphicsDevice, backgroundRemovedFrame.Width, backgroundRemovedFrame.Height); // Set the image we display to point to the bitmap where we'll put the image data //this.MaskedColor.Source = this.foregroundBitmap; } // 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); //this.foregroundBitmap.SetData<byte>(backgroundRemovedFrame.GetRawPixelData()); backgroundRemovedFrame.CopyPixelDataTo(depthPixelsData); bNeedsToRedrawDepth = true; } } }
/// <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); // Set the image we display to point to the bitmap where we'll put the image data this.MaskedColor.Source = this.foregroundBitmap; this.isUserEngaged = true; // Console.WriteLine("Yes for track id"); } else { this.isUserEngaged = false; // this.CurrentTimerCount = 0; //Console.WriteLine("reset timer ........... "); } // 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); } } }
void backgroundstream_BackgroundRemovedFrameReady(object sender, BackgroundRemovedColorFrameReadyEventArgs e) { using (var backgroundRemovedFrame = e.OpenBackgroundRemovedColorFrame()) { if (backgroundRemovedFrame != null) { lock (m_lock) { backgroundRemovedFrame.CopyPixelDataTo(this.bgdata); } this.frameindex = (int)backgroundRemovedFrame.Timestamp; } } }