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切换边,因为代码在图像数据字节的基础上固定了一个字节指针,然后从该值创建一个整数指针。这意味着要将单个像素的所有数据字节从一个地方复制到另一个地方,程序可以使用一条语句:*toPos = *fromPos;

资源

于 2013-08-15T19:09:54.533 回答