我正在与Kinect合作进行一项研究项目,直到现在我还在搞乱骨架跟踪。现在我进入了深度流的深处,我想知道如何创建我们在一些深度流中看到的RGB色标。我的是灰色的。有深度事件的一部分,我不明白,我觉得这是非常重要的,了解它是如何工作的,以及我如何将其改为颜色,它是intesity变量的定义。
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);
}
}
}
答案 0 :(得分: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;