How to get data using cols and rows as parameters in DepthFrame? (Unity3D)

I found byte[] Data, but it is One-dimensional array.

I want to turn this data into a 2D array.

I need help.

Hello. I think this tutorial can help https://github.com/3DiVi/nuitrack-sdk/blob/master/doc/Unity_Point_Cloud.md
Short sample:

        nuitrack.DepthFrame depthFrame = NuitrackManager.DepthFrame;
        print(depthFrame.Cols);
        print(depthFrame.Rows);
        print(depthFrame[300, 350]); //you can get depth from any point of frame (1D and 2D)

        ushort[,] depth = new ushort[depthFrame.Rows, depthFrame.Cols];
        for (int i = 0; i < depthFrame.Rows; i++)
        {
            for (int j = 0; j < depthFrame.Cols; j++)
            {
                depth[i, j] = depthFrame[i, j];
            }
        }

Thanks,
I used this Code, but I have 2nd problem.

depthFrame.Cols return 640, depthFrame.Rows return 480.
but depthFrame[480, 0] has error : ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.

image

what is a problem?

This was my mistake.
I was typing rows and columns in reverse. Thank you!

1 Like