public void ColorFrameArrival(ColorFrame colorFrame, ref WriteableBitmap colorBitmap, double fps) { using (KinectBuffer colorBuffer = colorFrame.LockRawImageBuffer()) { colorBitmap.Lock(); int width = colorFrame.FrameDescription.Width; int height = colorFrame.FrameDescription.Height; // verify data and write the new color frame data to the display bitmap if ((width == colorBitmap.PixelWidth) && (height == colorBitmap.PixelHeight)) { colorFrame.CopyConvertedFrameDataToIntPtr( colorBitmap.BackBuffer, (uint)(width * height * 4), ColorImageFormat.Bgra); colorBitmap.AddDirtyRect(new System.Windows.Int32Rect(0, 0, colorBitmap.PixelWidth, colorBitmap.PixelHeight)); colorBitmap.Unlock(); colorFrame.CopyConvertedFrameDataToArray(colorPixelBuffer, ColorImageFormat.Bgra); if (colorRecording) { //Console.WriteLine("1"); Bitmap bitmapFrame; try { bitmapFrame = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); } catch (Exception e) { Console.WriteLine("Color Exception"); Console.WriteLine(e); System.GC.Collect(); bitmapFrame = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); } UtilityClass.ByteArrayToBitmap(ref bitmapFrame, colorPixelBuffer, width, height); cBitmap = bitmapFrame; colorBitmapBuffer.Enqueue(cBitmap); //Console.WriteLine("2"); frameCount++; //garbageCount++; if (fps < 16.0) { Console.WriteLine("fps droped"); colorBitmapBuffer.Enqueue(cBitmap); frameCount++; } } } } //Console.WriteLine("5"); }
public void BodyIndexFrameArrival(BodyIndexFrame bif, ref bool frameProcessed, double fps, WriteableBitmap bodyIndexBitmap) { // the fastest way to process the body index data is to directly access // the underlying buffer using (Microsoft.Kinect.KinectBuffer bodyIndexBuffer = bif.LockImageBuffer()) { int width = bif.FrameDescription.Width; int height = bif.FrameDescription.Height; // verify data and write the color data to the display bitmap if (((width * height) == bodyIndexBuffer.Size) && (width == bodyIndexBitmap.PixelWidth) && (height == bodyIndexBitmap.PixelHeight)) { ProcessBodyIndexFrameData(bodyIndexBuffer.UnderlyingBuffer, bodyIndexBuffer.Size); frameProcessed = true; } if (bodyRecording) { Bitmap bitmapFrame; try { bitmapFrame = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); } catch (Exception e) { Console.WriteLine("Body Exception"); Console.WriteLine(e); System.GC.Collect(); bitmapFrame = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); } UtilityClass.ByteArrayToBitmap(ref bitmapFrame, bodyPixelBuffer, width, height); bBitmap = bitmapFrame; bodyBitmapBuffer.Enqueue(bBitmap); //System.GC.Collect(); frameCount++; if (fps < 16.0) { Console.WriteLine("fps drop yaşandı"); bodyBitmapBuffer.Enqueue(bBitmap); frameCount++; } } } }