Visualizing zed2i pointcloud using o3d

Hey everyone!

As the title implies, I’m currently trying to visualize zed pointcloud data using o3d in real time. At the moment, the visualizer only displays a blank white screen. I can’t seem to find any information on this online however, the code I’m using is below.

The end goal is to be able to use the pointcloud data in open3D. I originally tried to use ROS2 foxy, however, I couldn’t find a way to convert PointCloud2 data to something usable for open3d.

import pyzed.sl as sl
import open3d as o3d

# Initialize the ZED camera
init_params = sl.InitParameters()
init_params.camera_resolution = sl.RESOLUTION.HD720  # Set your desired resolution
zed = sl.Camera()
if not zed.is_opened():
    zed.open(init_params)

# Create an Open3D visualizer
vis = o3d.visualization.Visualizer()
vis.create_window()

try:
    while True:
        # Capture a frame
        runtime_parameters = sl.RuntimeParameters()
        if zed.grab(runtime_parameters) == sl.ERROR_CODE.SUCCESS:
            # Retrieve the point cloud
            point_cloud = sl.Mat()
            zed.retrieve_measure(point_cloud, sl.MEASURE.XYZRGBA)

            # Get the point cloud data as a numpy array
            point_cloud_data = point_cloud.get_data()

            # Extract the XYZ data
            xyz_data = point_cloud_data[:, :, :3]
            xyz_data = xyz_data.reshape(-1,3)

            # Create an Open3D point cloud
            point_cloud_o3d = o3d.geometry.PointCloud()
            point_cloud_o3d.points = o3d.utility.Vector3dVector(xyz_data)

            # Add the point cloud to the visualizer
            vis.add_geometry(point_cloud_o3d)

            # Update the visualization
            vis.update_geometry(point_cloud_o3d)
            vis.poll_events()
            vis.update_renderer()

except KeyboardInterrupt:
    # Exit the loop when a keyboard interrupt (e.g., Ctrl+C) is detected
    pass

# Close the ZED camera and the visualizer
zed.close()
vis.destroy_window()

Any assistance would be amazing!

Hi,

Sorry, I don’t know how open3d works. But it’s probably a matter of conversion betwwen the SDK format, and what open3d expects. More info about the ZED SDK point clouds here : MEASURE Class Reference | API Reference | Stereolabs

Hello,

Did you solve this? Very interested :slight_smile:

Thanks a lot!