Colors 从Kinect深度流获取像素颜色

Colors 从Kinect深度流获取像素颜色,colors,kinect,pixels,kinect-sdk,Colors,Kinect,Pixels,Kinect Sdk,我现在很难从Kinect深度流中找到特定像素的颜色。下面的代码是我用来计算(100100)处像素颜色的代码 我有一种感觉,我的逻辑在某个地方有缺陷(可能是在计算我想要的彩色像素的索引时) colorPixels和depthPixels声明如下: colorFrame.CopyPixelDataTo(colorPixels); //colorPixels is a byte[] depthFrame.CopyDepthImagePixelDataTo(depthPixels); //depthPi

我现在很难从Kinect深度流中找到特定像素的颜色。下面的代码是我用来计算(100100)处像素颜色的代码

我有一种感觉,我的逻辑在某个地方有缺陷(可能是在计算我想要的彩色像素的索引时)

colorPixels和depthPixels声明如下:

colorFrame.CopyPixelDataTo(colorPixels); //colorPixels is a byte[]
depthFrame.CopyDepthImagePixelDataTo(depthPixels); //depthPixels is a DepthImagePixel[]
DepthImagePoint ballDepthPoint = new DepthImagePoint();
int ballPosX = 100;
int ballPosY = 100;
int blueTotal = 0, greenTotal = 0, redTotal = 0;

ColorImagePoint ballColorPoint;

//build a depth point to translate to a color point
ballDepthPoint.X = ballPosX;
ballDepthPoint.Y = ballPosY;
ballDepthPoint.Depth = this.depthPixels[ballDepthPoint.X * ballDepthPoint.Y].Depth;

//work out the point on the color image from this depth point
ballColorPoint = this.sensor.CoordinateMapper.MapDepthPointToColorPoint(this.sensor.DepthStream.Format, ballDepthPoint, this.sensor.ColorStream.Format);

//extract the rgb values form the color pixels array
blueTotal += (int)colorPixels[(ballColorPoint.X * ballColorPoint.Y * colorFrame.BytesPerPixel)];
greenTotal += (int)colorPixels[(ballColorPoint.X * ballColorPoint.Y * colorFrame.BytesPerPixel) + 1];
redTotal += (int)colorPixels[(ballColorPoint.X * ballColorPoint.Y * colorFrame.BytesPerPixel) + 2];

System.Console.WriteLine("The ball found is " + redTotal + "," + blueTotal + "," + greenTotal + " which is " + Helper.ColorChooser(redTotal, greenTotal, blueTotal)); 
public static String ColorChooser(int r, int g, int b)
    {

        if (r >= g && r >= b)
        {
            return "RED";
        }
        else if (b >= g && b >= r)
        {
            return "BLUE";
        }
        else
            return "GREEN";
    }
我计算深度流中100100处像素的rgb值,如下所示:

colorFrame.CopyPixelDataTo(colorPixels); //colorPixels is a byte[]
depthFrame.CopyDepthImagePixelDataTo(depthPixels); //depthPixels is a DepthImagePixel[]
DepthImagePoint ballDepthPoint = new DepthImagePoint();
int ballPosX = 100;
int ballPosY = 100;
int blueTotal = 0, greenTotal = 0, redTotal = 0;

ColorImagePoint ballColorPoint;

//build a depth point to translate to a color point
ballDepthPoint.X = ballPosX;
ballDepthPoint.Y = ballPosY;
ballDepthPoint.Depth = this.depthPixels[ballDepthPoint.X * ballDepthPoint.Y].Depth;

//work out the point on the color image from this depth point
ballColorPoint = this.sensor.CoordinateMapper.MapDepthPointToColorPoint(this.sensor.DepthStream.Format, ballDepthPoint, this.sensor.ColorStream.Format);

//extract the rgb values form the color pixels array
blueTotal += (int)colorPixels[(ballColorPoint.X * ballColorPoint.Y * colorFrame.BytesPerPixel)];
greenTotal += (int)colorPixels[(ballColorPoint.X * ballColorPoint.Y * colorFrame.BytesPerPixel) + 1];
redTotal += (int)colorPixels[(ballColorPoint.X * ballColorPoint.Y * colorFrame.BytesPerPixel) + 2];

System.Console.WriteLine("The ball found is " + redTotal + "," + blueTotal + "," + greenTotal + " which is " + Helper.ColorChooser(redTotal, greenTotal, blueTotal)); 
public static String ColorChooser(int r, int g, int b)
    {

        if (r >= g && r >= b)
        {
            return "RED";
        }
        else if (b >= g && b >= r)
        {
            return "BLUE";
        }
        else
            return "GREEN";
    }
ColorChooser方法如下所示:

colorFrame.CopyPixelDataTo(colorPixels); //colorPixels is a byte[]
depthFrame.CopyDepthImagePixelDataTo(depthPixels); //depthPixels is a DepthImagePixel[]
DepthImagePoint ballDepthPoint = new DepthImagePoint();
int ballPosX = 100;
int ballPosY = 100;
int blueTotal = 0, greenTotal = 0, redTotal = 0;

ColorImagePoint ballColorPoint;

//build a depth point to translate to a color point
ballDepthPoint.X = ballPosX;
ballDepthPoint.Y = ballPosY;
ballDepthPoint.Depth = this.depthPixels[ballDepthPoint.X * ballDepthPoint.Y].Depth;

//work out the point on the color image from this depth point
ballColorPoint = this.sensor.CoordinateMapper.MapDepthPointToColorPoint(this.sensor.DepthStream.Format, ballDepthPoint, this.sensor.ColorStream.Format);

//extract the rgb values form the color pixels array
blueTotal += (int)colorPixels[(ballColorPoint.X * ballColorPoint.Y * colorFrame.BytesPerPixel)];
greenTotal += (int)colorPixels[(ballColorPoint.X * ballColorPoint.Y * colorFrame.BytesPerPixel) + 1];
redTotal += (int)colorPixels[(ballColorPoint.X * ballColorPoint.Y * colorFrame.BytesPerPixel) + 2];

System.Console.WriteLine("The ball found is " + redTotal + "," + blueTotal + "," + greenTotal + " which is " + Helper.ColorChooser(redTotal, greenTotal, blueTotal)); 
public static String ColorChooser(int r, int g, int b)
    {

        if (r >= g && r >= b)
        {
            return "RED";
        }
        else if (b >= g && b >= r)
        {
            return "BLUE";
        }
        else
            return "GREEN";
    }
如果您需要更多信息/代码,请告诉我

非常感谢,


Dave McB最终达到了这一点,用彩色像素索引像素的正确方法似乎是:

colorPixels[(ballColorPoint.X * colorFrame.BytesPerPixel) + (ballColorPoint.Y * stride)];
其中:

int stride = colorFrame.BytesPerPixel * colorFrame.Width;

这是Kinect编程书中的一个例子吗?我想我以前见过。嘿,戴夫,你首先用什么来读取深度数据流?我会假设微软的专有工具,但我想确定。