Point cloud data is wrong, how to solve it?

Hi!
When I run the depth_sensing, I add the code:

cloud = point_cloud_to_save.get_data()

Cloud is the form of ndarray data, and it is (720,1080,4) shape, but I found that there are some problems with this data, for example, some values are nan values, and some color values overflow, like this:

屏幕截图 2023-10-09 154130

Also when I run depth_sensing, it seems normal from the OpenGL window.

Hope someone can help me with this.
Thank you!

Hi @zore017
what you see is expected.

nan values correspond to pixels with no depth information (occlusions, flares, reflections, low confidence values, etc).

The fourth field is the color value in 32-bit format.
You must “read” it in the correct way, thus you must convert the float32 value to an array of four 8-bit values, the first is Blue, the second is Red, the third is Green, and the last is Alpha (transparency level).

You can for example use Numpy:

import numpy as np


def float32_to_uint8_array(float32_value):
  """Converts a float32 value to an array of 4 8bit values.

  Args:
    float32_value: A float32 value.

  Returns:
    An array of 4 8bit values.
  """

  # Convert the float32 value to a uint32 value.
  uint32_value = np.uint32(float32_value)

  # Split the uint32 value into 4 8bit values.
  uint8_values = np.unpackbits(uint32_value, axis=0)[::-1]

  return uint8_values

Example usage:

float32_value = 0.5
uint8_values = float32_to_uint8_array(float32_value)

print(uint8_values)