Depth image flickers when using Parallel.For
-
Wednesday, June 13, 2012 7:24 AM
I'm converting depth data from the Kinect into an image (Bgr565 format). When I iterate through the array of depth pixels (to map them to a color) using a standard for loop, i get a good smooth image. But when I use Parallel.For, I get a flickering image.
Here's the code section:
// === 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; } );
Any hints as to why this is happening would be greatly welcome!
All Replies
-
Friday, June 15, 2012 12:45 AMOwnerUse Kinect Studio to record some frames and play that back alternating between methods. Since the recording is constant, you should be able to step through your code and see if any of the values change. They should be the same. In the Parrellel.For, there is nothing Kinect specific you are using since I have to assume depthPixelArray and colorPixelsArray are short/byte arrays, which are regular data types.

