python - open3d 中的 pointcloud2 流可视化或其他在 python 中可视化 pointcloud2 的可能性
问题描述
我正在尝试通过 python 中的 open3d 可视化来自 rostopic 的 pointcloud2 流。
这是我的代码:
import sensor_msgs.point_cloud2 as pc2
import open3d
...
def callback(self, points):
#self.pc = pcl.VoxelGridFilter(self.pc)
self.pc = self.convertCloudFromRosToOpen3d(points)
if self.first:
self.first = False
self.vis.create_window()
rospy.loginfo('plot')
self.vis.add_geometry(self.pc)
self.vis.update_geometry()
self.vis.poll_events()
self.vis.update_renderer()
self.vis.run()
else:
rospy.loginfo('update')
self.vis.update_geometry()
self.vis.poll_events()
self.vis.update_renderer()
self.vis.run()
def listener(self):
rospy.init_node('ui_config_node', anonymous=True)
rospy.Subscriber('/kinect2/sd/points', PointCloud2, self.callback)
rospy.spin()
如果我启动这段代码,我只会得到一张冻结的图片。
我使用此脚本将 pointCloud2 转换为 open3d 格式。
如果有人有另一个想法来可视化 rospy 中的 pointcloud2,我会很高兴听到它。
感谢您的帮助和建议!
解决方案
我想到了。rospy.spin()
块可视化。
所以我的最终代码
罗斯节点:
if __name__ == '__main__':
listener = CameraListner()
updater = Viewer(listener)
rospy.spin()
相机监听器
class CameraListner():
def __init__(self):
self.pc = None
self.n = 0
self.listener()
############################################################################
def callback(self, points):
self.pc = points
self.n = self.n + 1
def listener(self):
rospy.init_node('ui_config_node', anonymous=True)
rospy.Subscriber('/kinect2/sd/points', PointCloud2, self.callback)
至少是查看器类
class ViewerWidget(QtWidgets.QWidget):
def __init__(self, subscriber, parent=None):
self.subscriber = subscriber
rospy.loginfo('initialization')
self.vis = open3d.visualization.Visualizer()
self.point_cloud = None
self.updater()
############################################################################
def updater(self):
rospy.loginfo('start')
self.first = False
while (self.subscriber.pc is None):
time.sleep(2)
self.point_cloud = open3d.geometry.PointCloud()
self.point_cloud.points = open3d.utility.Vector3dVector(ros_numpy.point_cloud2.pointcloud2_to_xyz_array(self.subscriber.pc))
self.vis.create_window()
print('get points')
self.vis.add_geometry(self.point_cloud)
print ('add points')
self.vis.update_geometry()
self.vis.poll_events()
self.vis.update_renderer()
while not rospy.is_shutdown():
self.point_cloud.points = open3d.utility.Vector3dVector(ros_numpy.point_cloud2.pointcloud2_to_xyz_array(self.subscriber.pc))
self.vis.update_geometry()
self.vis.poll_events()
self.vis.update_renderer()
我还更改了将 PointCloud2 转换为 o3d 点云的方法
推荐阅读
- javascript - IPFS 应用程序中超出了最大调用堆栈。当 IPFS API 调用连续两次时
- javascript - 歌曲和弦歌词格式预览不起作用
- windows - 通过代理从个人计算机访问公共 PostgreSQL 服务器 (Amazon RDS)
- azure - 获取 azure 磁盘信息 csv
- plotly - Plotly:渲染 3D 网格椭圆体时的视觉伪影
- reactjs - 在 React 中提交表单后如何显示消息?
- java - Java - 在本机查询中设置 currentDate 时间?
- vue.js - 如何在 vue-cli 项目上没有任何新库和配置的情况下将 png 文件导入为 base64 字符串?
- c++ - 为什么 C++ 中 size_t 和 unsigned int 的混合模除会出错
- docker - 复制 docker 卷