Coverage for src/evutils/vis/open3d.py: 46%
13 statements
« prev ^ index » next coverage.py v7.15.1, created at 2026-07-18 05:24 +0000
« prev ^ index » next coverage.py v7.15.1, created at 2026-07-18 05:24 +0000
1"""Open3D visualization utilities for event camera data.
3This module provides functions to visualize event streams in 3D (x, y, time)
4using Open3D.
6``open3d`` and ``matplotlib`` are imported lazily, inside the functions that
7use them, so importing this module stays cheap.
8"""
9import numpy as np
11def o3d_draw_events(events: np.ndarray) -> None:
12 """Visualizes events using Open3D.
14 Parameters
15 ----------
16 events : np.ndarray
17 Array of events with fields 'x', 'y', 't', and 'p'.
18 'x' and 'y' are the pixel coordinates, 't' is the timestamp, and 'p' is the polarity.
20 Returns
21 -------
22 None
24 """
25 import open3d as o3d
26 from matplotlib import pyplot as plt
28 if len(events) == 0:
29 return
31 # Draw X, Y, T as a pointcloud
32 pdc = o3d.geometry.PointCloud()
34 time_diff = np.max(events['t']) - np.min(events['t'])
35 # Normalize time to range 0..3000
36 norm_time = (events['t'] - np.min(events['t'])) / time_diff * 3000
38 pdc.points = o3d.utility.Vector3dVector(np.column_stack((events['x'], events['y'], norm_time)))
40 # Create a color map based on the 'p'
41 # p can be either 0 or 1, we use it to color the points witht eh Spectral colormap
42 colors = plt.cm.Spectral(events['p'].astype(np.float32))[:, :3] # Use only RGB channels
44 pdc.colors = o3d.utility.Vector3dVector(colors)
46 o3d.visualization.draw_geometries([pdc])