使用 Parallel.For 处理时 Kinect 深度图像闪烁

本文关键字:深度 深度图 图像 闪烁 Kinect Parallel For 处理 使用 | 更新日期: 2023-09-27 18:37:17

我正在将来自 Kinect 的深度数据转换为图像(Bgr565 格式)。当我使用标准的 for 循环遍历深度像素数组(将它们映射到颜色)时,我得到了一个很好的平滑图像。但是当我使用Parallel.For时,我得到一个闪烁的图像。

下面是代码部分。任何帮助将不胜感激:

// === Single-threaded depth to color conversion ===
        for (int i = 0; i < depthPixelsArray.Length; ++i)
        {
            depth = (short)(depthPixelsArray[i] >> DepthImageFrame.PlayerIndexBitmaskWidth);
            if (depth >= colorBoundary)
                unchecked { colorPixelsArray[i] = (short)0xF800; }
            else colorPixelsArray[i] = depth;
        }
// === Multi-threaded depth to color conversion ===
 Parallel.For (0, depthPixelsArray.Length, delegate(int i)
            {
                depth = (short)(depthPixelsArray[i] >> DepthImageFrame.PlayerIndexBitmaskWidth);
                if (depth >= colorBoundary)
                    unchecked { colorPixelsArray[i] = (short)0xF800; }
                else colorPixelsArray[i] = depth;
            }
            );

使用 Parallel.For 处理时 Kinect 深度图像闪烁

如果您在

并行处理进行时渲染它们,似乎可能会发生这种情况。在单线程情况下,渲染和处理可能是顺序操作,因此看起来都不错。当您调用 Parallel.因为您得到的只是一个 ParallelLoopResult 但循环尚未完成。渲染此静止处理结果可能是闪烁的原因。在继续渲染之前,您需要确保在结果上设置了 IsComplete。

希望对您有所帮助!