当前位置: 首页>>代码示例>>C#>>正文


C# CoordinateMapper.MapDepthFrameToColorFrame方法代码示例

本文整理汇总了C#中CoordinateMapper.MapDepthFrameToColorFrame方法的典型用法代码示例。如果您正苦于以下问题:C# CoordinateMapper.MapDepthFrameToColorFrame方法的具体用法?C# CoordinateMapper.MapDepthFrameToColorFrame怎么用?C# CoordinateMapper.MapDepthFrameToColorFrame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CoordinateMapper的用法示例。


在下文中一共展示了CoordinateMapper.MapDepthFrameToColorFrame方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SensorDepthFrameReady

        /// <summary>
        /// Event handler for Kinect sensor's DepthFrameReady event
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void SensorDepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
        {
            using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
            {
                if (depthFrame != null)
                {
                    // Copy the pixel data from the image to a temporary array
                    depthFrame.CopyDepthImagePixelDataTo(this.depthPixels);

                    // calculate the mapping
                    CoordinateMapper mapper = new CoordinateMapper(this.sensor);
                    mapper.MapDepthFrameToColorFrame(
                        DepthImageFormat.Resolution640x480Fps30,
                        this.depthPixels,
                        ColorImageFormat.RgbResolution640x480Fps30,
                        colorCoordinates);

                    // Get the min and max reliable depth for the current frame
                    int minDepth = depthFrame.MinDepth;
                    int maxDepth = depthFrame.MaxDepth;

                    // Convert the depth to RGB
                    int colorPixelIndex = 0;
                    for (int i = 0; i < this.depthPixels.Length; ++i)
                    {
                        // Get the depth for this pixel
                        short depth = depthPixels[i].Depth;
                        this.depthPixelsCopy[i] = (depth >= minDepth && depth <= maxDepth ? depth : (short)0);

                        // To convert to a byte, we're discarding the most-significant
                        // rather than least-significant bits.
                        // We're preserving detail, although the intensity will "wrap."
                        // Values outside the reliable depth range are mapped to 0 (black).

                        // Note: Using conditionals in this loop could degrade performance.
                        // Consider using a lookup table instead when writing production code.
                        // See the KinectDepthViewer class used by the KinectExplorer sample
                        // for a lookup table example.
                        long intensity = (depth >= minDepth && depth <= maxDepth ? depth : 0);

                        double value = (double)(intensity - minDepth) / (maxDepth - minDepth);

                        // Write out blue byte
                        this.depthPseudoColorPixels[colorPixelIndex++] = intensity == 0 ? (byte)100 : (byte)(255 * Blue(value));

                        // Write out green byte
                        this.depthPseudoColorPixels[colorPixelIndex++] = intensity == 0 ? (byte)100 : (byte)(255 * Green(value));

                        // Write out red byte
                        this.depthPseudoColorPixels[colorPixelIndex++] = intensity == 0 ? (byte)100 : (byte)(255 * Red(value));

                        // We're outputting BGR, the last byte in the 32 bits is unused so skip it
                        // If we were outputting BGRA, we would write alpha here.
                        ++colorPixelIndex;
                    }

                    // Write the pixel data into our bitmap
                    this.depthPseudoColorBitmap.WritePixels(
                        new Int32Rect(0, 0, this.depthPseudoColorBitmap.PixelWidth, this.depthPseudoColorBitmap.PixelHeight),
                        this.depthPseudoColorPixels,
                        this.depthPseudoColorBitmap.PixelWidth * sizeof(int),
                        0);

                    for (int i = 0; i < this.sensor.DepthStream.FrameHeight; i++)
                    {
                        for (int j = 0; j < this.sensor.DepthStream.FrameWidth; j++)
                        {
                            int pos1 = i * this.sensor.DepthStream.FrameWidth + j;
                            int pos2 = i * this.sensor.DepthStream.FrameWidth + (this.sensor.DepthStream.FrameWidth - 1 - j);

                            short depth = depthPixels[pos2].Depth;
                            depth = (depth >= minDepth && depth <= maxDepth ? depth : (short) 0);

                           this.depthPixelsCopy[pos1] = depth;
                        }
                    }

                }
            }
        }
开发者ID:shengshuyang,项目名称:WindowsProjects,代码行数:85,代码来源:MainWindow.xaml.cs


注:本文中的CoordinateMapper.MapDepthFrameToColorFrame方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。