【问题标题】:Creating oposite Mirror picture by manipulate Kinect Color pixels通过操作 Kinect 颜色像素创建对面镜像图片
【发布时间】:2013-08-16 03:09:54
【问题描述】:

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

【问题讨论】:

    标签: c# kinect kinect-sdk


    【解决方案1】:

    创建反射的代码是

    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;

    Source

    【讨论】:

    • 这不会交换字节,toPos 的值现在在被 fromPos 覆盖时会丢失。要正确交换值,您应该在循环外添加一个临时缓冲区整数,并在循环中将 toPos 值复制到缓冲区,然后将 fromPos 分配给 toPos,最后将临时分配给 fromPos。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多