通过操纵Kinect Color像素创建opsite镜像图片

本文关键字:opsite 镜像 创建 像素 操纵 Kinect Color | 更新日期: 2023-09-27 18:27:43

我正试图从颜色流中创建一个相反的镜像图片,即,当右手向上移动时,我希望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 { 

        }
    }

有人能告诉我发生了什么事吗?谢谢erez

通过操纵Kinect Color像素创建opsite镜像图片

创建反射的代码是

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;