private void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e) { if (!(KinectStreamerConfig.StreamBodyData || KinectStreamerConfig.StreamColorData || KinectStreamerConfig.StreamDepthData || KinectStreamerConfig.StreamPointCloudData || KinectStreamerConfig.ProvideCalibrationData || KinectStreamerConfig.StreamColoredPointCloudData )) { return; } depthFrame = null; colorFrame = null; bodyFrame = null; bodyStreamMessage = null; colorStreamMessage = null; pointCloudStreamMessage = null; depthStreamMessage = null; calibrationDataMessage = null; coloredPointCloudStreamMessage = null; multiSourceFrame = e.FrameReference.AcquireFrame(); // If the Frame has expired by the time we process this event, return. if (multiSourceFrame == null) { return; } // We use a try/finally to ensure that we clean up before we exit the function. // This includes calling Dispose on any Frame objects that we may have and unlocking the bitmap back buffer. try { depthFrame = multiSourceFrame.DepthFrameReference.AcquireFrame(); colorFrame = multiSourceFrame.ColorFrameReference.AcquireFrame(); //Debug.Write(colorFrame.RelativeTime.ToString()); bodyFrame = multiSourceFrame.BodyFrameReference.AcquireFrame(); // If any frame has expired by the time we process this event, return. // The "finally" statement will Dispose any that are not null. if ((depthFrame == null) || (colorFrame == null) || (bodyFrame == null)) { return; } // Process color stream if needed if (KinectStreamerConfig.StreamColorData || KinectStreamerConfig.StreamColoredPointCloudData) { ProcessColorData(); } // Process depth frame if needed if (KinectStreamerConfig.StreamDepthData || KinectStreamerConfig.StreamPointCloudData || KinectStreamerConfig.StreamColoredPointCloudData) { ProcessDepthData(); if (KinectStreamerConfig.StreamPointCloudData || KinectStreamerConfig.StreamColoredPointCloudData) { GenerateFullPointCloud(); } } if (KinectStreamerConfig.StreamColoredPointCloudData) { ProcessPointCloudColors(); } // Process body data if needed if (KinectStreamerConfig.StreamBodyData || KinectStreamerConfig.ProvideCalibrationData) { ProcessBodyData(); } SendData(); } finally { if (depthFrame != null) { depthFrame.Dispose(); } if (colorFrame != null) { colorFrame.Dispose(); } if (bodyFrame != null) { bodyFrame.Dispose(); } } }
private void ProcessColorData() { using (colorFrame) { if (colorFrame != null) { ColorFrameDescription = colorFrame.FrameDescription; using (colorFrame.LockRawImageBuffer()) { colorBitmap.Lock(); // verify data and write the new color frame data to the display bitmap if ((ColorFrameDescription.Width == colorBitmap.PixelWidth) && (ColorFrameDescription.Height == colorBitmap.PixelHeight)) { colorFrame.CopyConvertedFrameDataToArray( colorPixels, ColorImageFormat.Bgra); } colorBitmap.Unlock(); } } } colorStreamMessage = new ColorStreamMessage(colorPixels, new FrameSize(ColorFrameDescription.Width, ColorFrameDescription.Height)); }