せっかく点群も取れるので、そちらも試してみることに
実際のところ
$ pip install plotly $ pip install open3d
import numpy as np import rclpy from sensor_msgs.msg import PointCloud2 from sensor_msgs import point_cloud2 import plotly.express as px # 点群データを保存するための変数 cloud_points = [] # 点群データのコールバック関数 def callback(msg): global cloud_points # 点群データを読み込む cloud_points = list(point_cloud2.read_points(msg, field_names=("x", "y", "z"), skip_nans=True)) # rclpyを初期化 rclpy.init() # ノードの作成 node = rclpy.create_node('pointcloud_listener') # 点群データのトピックをサブスクライブ subscription = node.create_subscription(PointCloud2, '/camera/depth/color/points', callback, 10) # 一度だけコールバックを実行 rclpy.spin_once(node) # 点群データをnumpy配列に変換 cloud_array = np.array(cloud_points) # 点群データをplotlyで可視化 fig = px.scatter_3d(x=cloud_array[:, 0], y=cloud_array[:, 1], z=cloud_array[:, 2], opacity=0.5) fig.show()