none
Depth image flickers when using Parallel.For RRS feed

  • Question

  • 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!




    • Edited by dialAlpha Wednesday, June 13, 2012 7:48 AM
    Wednesday, June 13, 2012 7:24 AM

All replies

  • Use 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. 
    Friday, June 15, 2012 12:45 AM