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 ProcessDepthData() { using (depthFrame) { if (depthFrame != null) { // the fastest way to process the body index data is to directly access // the underlying buffer using (KinectBuffer depthBuffer = depthFrame.LockImageBuffer()) { // verify data and write the color data to the display bitmap if (((DepthFrameDescription.Width * DepthFrameDescription.Height) == (depthBuffer.Size / DepthFrameDescription.BytesPerPixel)) && (DepthFrameDescription.Width == depthBitmap.PixelWidth) && (DepthFrameDescription.Height == depthBitmap.PixelHeight)) { // Note: In order to see the full range of depth (including the less reliable far field depth) // we are setting maxDepth to the extreme potential depth threshold ushort maxDepth = ushort.MaxValue; // If you wish to filter by reliable depth distance, uncomment the following line: //// maxDepth = depthFrame.DepthMaxReliableDistance ProcessDepthFrameData(depthBuffer.UnderlyingBuffer, depthBuffer.Size, depthFrame.DepthMinReliableDistance, maxDepth); } } } } depthStreamMessage = new DepthStreamMessage(DepthPixels, new FrameSize(DepthFrameDescription.Width, DepthFrameDescription.Height)); }