0

私はカラー ストリームから反対側の鏡像を作成しようとしています。つまり、右手が上に移動しているときに、左手が上に移動しなければならないように kinect が描画するようにします (右手が上げている実際の鏡の前とは異なります)。それを行うためにカラー画像を操作したい:X位置を移動するだけです。ただし、ブルースクリーンが表示されます:

    void kinectSensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
    {
        try
        {
               using (ColorImageFrame colorImageFrame = e.OpenColorImageFrame())
            {
                if (colorImageFrame != null)
                {
                    byte[] pixelsFromFrame = new byte[colorImageFrame.PixelDataLength];
                     colorImageFrame.CopyPixelDataTo(pixelsFromFrame);
                     Color[] color = new Color[colorImageFrame.Height * colorImageFrame.Width];
                    kinectRGBVideo = new Texture2D(graphics.GraphicsDevice, colorImageFrame.Width, colorImageFrame.Height);

                    // Go through each pixel and set the bytes correctly
                    // Remember, each pixel got a Rad, Green and Blue
                    int index = 0;
                    for (int y = 0; y < colorImageFrame.Height; y++)
                    {
                        for (int x = 0; x < colorImageFrame.Width; x++, index += 4)
                        {
                            color[(y * colorImageFrame.Width + x)] = new Color(pixelsFromFrame[(y+1)*(2560 -index)],
                                pixelsFromFrame[(y + 1) * (2560 - index)],
                                pixelsFromFrame[(y + 1) * (2560 - index)]);
                         }
                    }
                               // Set pixeldata from the ColorImageFrame to a Texture2D
                   kinectRGBVideo.SetData(color);


                }
            }
        }
        catch { 


        }
    }

wearg とは誰か教えてもらえますか? ありがとう

4

1 に答える 1

0

反射を作成するコードは次のとおりです。

unsafe void reflectImage(byte[] colorData, int width, int height)
{
    fixed (byte* imageBase = colorData)
    {
        // Get the base position as an integer pointer
        int* imagePosition = (int*)imageBase;
        // repeat for each row
        for (int row = 0; row < height; row++)
        {
            // read from the left edge
            int* fromPos = imagePosition + (row * width);
            // write to the right edge
            int* toPos = fromPos + width - 1;
            while (fromPos < toPos)
            {
                *toPos = *fromPos;
                 //copy the pixel
                 fromPos++; // move towards the middle
                 toPos--; // move back from the right edge
            }
        }
    }
}

これは、コードがイメージ データ バイトのベースにバイト ポインターを固定し、その値から整数ポインターを作成するため、バイトが入れ替わるようになりますtoPosfromPosこれは、1 つのピクセルのすべてのデータ バイトをある場所から別の場所にコピーするために、プログラムで 1 つのステートメントを使用できることを意味します。*toPos = *fromPos;

ソース

于 2013-08-15T19:09:54.533 に答える