How do i change the color of depth visualization

I am new to nuitrack and am having trouble changing the depth sensor color and it seems to be stuck on red. Ive tried messing around with the values in the code as shown below but to no avail.

Manual conversion of frames to Unity Texture is outdated and not advisable.

Use the extension methods ToTexture(), ToTexture2D(), or ToRenderTexture() for ColorFrame, DepthFrame, or UserFrame.

Example:

using NuitrackSDK.Frame; // extension methods are contained in this namespace.

...

depthTexture = depthFrame.ToTexture2D();
rgbTexture = colorFrame.ToTexture2D();

If you need to change the color exactly, then change this line

//take depth from the frame and put it into the depthColors array
depthColors[pointIndex].r = depthFrame[i, j] / 16384f;

Hi Eugene, so far what ive tried was to change
depthColors[pointIndex].r = depthFrame[i, j] / 16384f;
result:


to

depthColors[pointIndex].g = depthFrame[i, j] / 16384f;
result


and upon doing so the display turns black and nothing is shown which wouldnt make sense as im only changing the color

You need to change the texture format in the line:

depthTexture = new Texture2D(cols, rows, TextureFormat.RFloat, false);

For example, on ARGB32 or RGB24 (check the correctness of converting the depth value to the selected format)

Thanks I managed to get it working but as of now I would like to get nuitrack to give me depth values in numbers and not just through color visualization is that possible? And if it is could i make the color change if in different depths.

The depthFrame structure is just a matrix, each value of which is a depth value in millimeters.
You can use depthFrame[i,j] this will be the depth [i, j] of the pixel in millimeters.

In the example we used:

depthFrame[i, j] / 16384f;

This means that we divided the depth by 16384 millimeters (approximately ~16 meters) to get an approximation to the normalized values (many sensors work up to 16 meters and we thought that this would be enough).

In fact, the use of this constant is outdated and not correct. In the DepthToTexture module (in the NuitrackScripts nested prefab), a variable denoting the maximum depth of the sensor is defined. It is recommended to use FrameUtils.DepthToTexture.MaxSensorDepth (name space NuitrackSDK.Frame)

Im currently using nuitrack version 0.35.8, is what you stated in the same place because i am unable to find it as well as when trying to print the value,


for some reason the value always shows as 0 unless i do

Is there any workaround or solution that you may have in mind?

We recommend using the latest version of NuitrackSDK (v0.35.11).

You need to convert the type correctly.

 float depthInMeters = (float)depthFrame[i, j] * 0.001f;

Your first example is incorrect, since it will print the last pixel of the depth map.

1 Like