简体   繁体   English

如何水平翻转Kinect v2颜色流?

[英]How can I flip the Kinect v2 colorstream horizontally?

I recently set-up my Kinect v2 on my win 10 PC. 我最近在Win 10 PC上安装了Kinect v2。 Intending to use it for some VR mixed reality streaming I have found that the video feed is mirrored and there is no way to flip it. 打算将其用于某些VR混合现实流中,我发现视频馈送已镜像并且无法翻转。

I have attempted to modify the Coordinate Mapping Basics program in the SDK to be a green screen and to flip the image. 我试图将SDK中的“坐标映射基础”程序修改为绿色屏幕并翻转图像。 The green I have done but I can not get the colorstream to flip! 我已经完成了绿色操作,但是无法使色流翻转!

I have tried turning the WriteableBitmap to a bitmap, exporting it an array then flipping the array and writing it back to a WritableBitmap but that didn't work. 我尝试过将WriteableBitmap转换为位图,将其导出为数组,然后翻转该数组并将其写回到WritableBitmap,但这没有用。

I have tried installing WriteableBitmapEx library and using the flip function but the program just freezes. 我尝试安装WriteableBitmapEx库并使用flip函数,但是该程序冻结了。

Any suggestions? 有什么建议么?

Long term I also want the program to act as a virtual webcam to pass the video feed straight to a compositor, but one step at a time. 从长远来看,我还希望该程序充当虚拟网络摄像头,将视频源直接传递给合成器,但每次只能传递一个步骤。

UPDATE: I Have got the image to flip BUT its at a HUGE performance hit. 更新:我已经获得了可以翻转图像的功能,但性能却非常出色。 Wrote this to convert the WriteableBitmap into a byte Array then reverse the order. 编写此代码以将WriteableBitmap转换为字节数组,然后颠倒顺序。 Doing some tests its the loop which is killing the performance. 做一些测试会破坏性能。 Any alternatives or ways to optimise the loop? 有没有其他选择或方法可以优化循环?

private void flipBitmap(int method)
    {            
        if (method == 1)//works but slow.
        {
            var width = this.bitmap.PixelWidth;
            var height = this.bitmap.PixelHeight;
            var stride = ((PixelFormats.Bgr32.BitsPerPixel + 7) / 8) * width;
            int current, flipped = 0;
            var raw= new byte[stride * height];
            this.bitmap.CopyPixels(bitmapData, stride, 0);
            var flippedPixels = new byte[raw.Length];
            for (int y = 0; y < height; y++)
            {

                for (int x = 4; x < width; x++)
                {
                    current = (y * stride) + (x * 4);
                    flipped = (y * stride) + (width - x) * 4;
                    for (int i = 0; i < 3; i++)
                    {
                        flippedPixels[flipped + i] = raw[current + i];
                    }
                    flippedPixels[flipped + 3] = 255;
                }
            }
            this.bitmap.WritePixels(new Int32Rect(0, 0, width, height), flippedPixels, stride, 0);
        }
        else if(method == 2)//placeholder
        {
            return;
        }
        else 
        {
            return;
        }                        
    }

UPDATE 2: I now have it running at what looks like 30fps. 更新2:现在,它以30fps的速度运行。 Just got to get the performance better! 只是要获得更好的性能! I pulled the variables out so it was not making new arrays all the time, just recycling the old ones. 我将变量拉出,这样就不会一直在制作新数组,而只是在回收旧数组。 Now thinking about running parallel for loops, one going from the start of the array, the other from the end. 现在考虑运行并行的for循环,一个从数组的开头开始,另一个从结尾开始。 No idea if that will speed it up or use more/less processing power. 不知道这是否会加快速度或使用更多/更少的处理能力。 Right now the program uses 40-50% of my cpu which is insane and much more than I can do as well as VR. 现在,该程序使用了我40%至50%的CPU,这太疯狂了,远远超过了VR所能达到的水平。 Still interested in faster/more efficient ways to flip the image if anyone has them. 仍然对更快/更有效的方式(如果有人拥有)翻转图像感兴趣。

UPDATE 3: With A little more tinkering and cleaning of old experiments the performance has improved but its still using twice the cpu the nonflipped version uses. 更新3:通过修补和清除旧的实验,性能有所提高,但仍使用非翻转版本使用的CPU两倍的性能。

private void flipBitmap(int method)
    {

        if (method == 1)//works but cpu intensive.
        {           
            int current, flipped = 0;
            this.bitmap.CopyPixels(raw, stride, 0);                

            for (int y = 0; y < height; y++)
            {

                for (int x = 4; x < width; x++)
                {
                    current = (y * stride) + (x * 4);
                    flipped = (y * stride) + (width - x) * 4;

                    flippedPixels[flipped + 0] = raw[current + 0];
                    flippedPixels[flipped + 1] = raw[current + 1];
                    flippedPixels[flipped + 2] = raw[current + 2];
                    flippedPixels[flipped + 3] = 255;                        
                }
            }
            this.bitmap.WritePixels(new Int32Rect(0, 0, width, height), flippedPixels, stride, 0);

            return;
        }
        else if(method == 2)//placeholder
        {               
            return;
        }
        else 
        {                
            return;
        }                        
    }

Have you tried this? 你有尝试过吗? https://msdn.microsoft.com/en-us/library/system.drawing.image.rotateflip(v=vs.110).aspx https://msdn.microsoft.com/zh-CN/library/system.drawing.image.rotateflip(v=vs.110).aspx

It looks like exactly what you're looking for... 看起来正是您想要的东西...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM