I’m using the ZED stereo depth camera in Unity, but I can’t figure out how to get at the depth values. Here is the loop where I’m trying to use the texture:
public Material depthMaterial;
private Texture2D depthTexture;
private float[,] depthValues;
private sl.ZEDCamera zedCam;
void Update()
{
depthTexture = zedCamera.CreateTextureImageType(sl.VIEW.DEPTH) as Texture2D;
depthMaterial.mainTexture = depthTexture;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
depthValues[i,j] = depthTexture.GetPixel(i,j).grayscale;
}
}
terrain.terrainData.SetHeights(0, 0, depthValues);
}
But I get the same value for every pixel. Same result with a version that used GetPixels and Color32. The texture does have the depth map in it, I confirmed by applying depthMaterial to a Quad in the scene.
This method gets me values that look like they might be what I’m after, but it is so slow that the program is unresponsive:
void Update()
{
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
depthValues[i,j] = zedCam.GetDepthValue((uint)i, (uint)j);
}
}
terrain.terrainData.SetHeights(0, 0, depthValues);
}