2

現在、Kinect Depth Stream から特定のピクセルの色を見つけようとして少し苦労しています。以下のコードは、(100, 100) のピクセルの色を計算するために使用しているものです。

私のロジックにどこか欠陥があるような気がします (おそらく、必要な colorPixels へのインデックスを計算するとき)

colorPixels と depthPixels は次のように宣言されます。

colorFrame.CopyPixelDataTo(colorPixels); //colorPixels is a byte[]
depthFrame.CopyDepthImagePixelDataTo(depthPixels); //depthPixels is a DepthImagePixel[]

次のように、深度ストリームの 100,100 のピクセルの RGB 値を計算します。

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

ColorChooser メソッドは次のとおりです。

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";
    }

さらに情報/コードが必要な場合はお知らせください。

どうもありがとう、

デイブ・マクブ

4

1 に答える 1

2

最後に、カラーピクセルのピクセルにインデックスを付ける正しい方法は次のようです。

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

どこ:

int stride = colorFrame.BytesPerPixel * colorFrame.Width;
于 2013-01-21T21:09:18.253 に答える