【问题标题】:Trying to transform Kinect Depth from gray scale to RGB according to distance尝试根据距离将 Kinect Depth 从灰度转换为 RGB
【发布时间】:2014-04-10 16:50:15
【问题描述】:

我正在使用 Kinect 进行一个研究项目,直到现在我只是在搞乱骨骼跟踪。现在我进入了深度流的深处,我想知道如何创建我们在某些深度流中看到的 RGB 色标。我的是灰度。深度事件的一部分我不理解,我觉得这对于理解它是如何工作的以及如何将其更改为颜色以及强度变量的定义非常重要。

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);

                // 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;

                    if (depth > 2000) depth = 0; //ive put this here just to test background elimination

                    byte intensity = (byte)(depth >= minDepth && depth <= maxDepth ? depth : 0);
                    //WHAT IS THIS LINE ABOVE DOING?

                    // Write out blue byte
                    this.colorPixels[colorPixelIndex++] = intensity;

                    // Write out green byte
                    this.colorPixels[colorPixelIndex++] = intensity;

                    // Write out red byte                        
                    this.colorPixels[colorPixelIndex++] = intensity;

                    // 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.colorBitmap.WritePixels(
                    new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight),
                    this.colorPixels,
                    this.colorBitmap.PixelWidth * sizeof(int),
                    0);
            }
        }
}

【问题讨论】:

  • 您是否找到了为深度图像着色的解决方案?
  • 最后我使用了我在 kinect 示例中找到的一个类,该文件名为 DepthColorizer.cs。查看您的具有深度着色的样本!

标签: c# kinect kinect-sdk


【解决方案1】:
byte intensity = (byte)(depth >= minDepth && depth <= maxDepth ? depth : 0);
//WHAT IS THIS LINE ABOVE DOING?

上面的行使用Ternary Operator

基本上它是一个单行 if 语句,相当于:

byte intensity;

if (depth >= minDepth && depth <= maxDepth) 
{
    intensity = (byte)depth;
}
else
{
    intensity = 0;
}

为深度图像着色的技巧是将强度乘以色调颜色。例如:

Color tint = Color.FromArgb(0, 255, 0) // Green

// Write out blue byte
this.colorPixels[colorPixelIndex++] = intensity * tint.B;

// Write out green byte
this.colorPixels[colorPixelIndex++] = intensity * tint.G;

// Write out red byte                        
this.colorPixels[colorPixelIndex++] = intensity * tint.R;

【讨论】:

  • 感谢您的解释,我提供了一些解决方案。我注意到使用大量条件句时速度有所放缓,但我认为您的回答已经解释得足够充分,谢谢。如果有人想分享他们关于为 kinect 着色的代码并给我提示,欢迎您。
猜你喜欢
  • 2013-07-30
  • 2020-04-29
  • 1970-01-01
  • 1970-01-01
  • 2010-10-15
  • 2013-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多