通过监听rostopic,解析并保存velodyne 激光雷达的三维数据,然后保存为txt格式;
#!/usr/bin/env python
# coding=utf-8
import rospy
from std_msgs.msg import String
from sensor_msgs.msg import PointCloud2
from sensor_msgs import point_cloud2
import time
def callback21(msg):
# import pcl
import numpy as np
points = point_cloud2.read_points_list(msg, field_names=("x", "y", "z"))
# pointsnp = np.array(list(points))
#cloud = pcl.PointCloud_PointXYZRGB()
pointsnp = np.zeros((307200, 3), dtype=np.float32)
# if cloud_count % 20 == 0:
n = 0
for p in points:
#print("Cloud x : %.3f y: %.3f z: %.3f" % (p[0], p[1], p[2]))
pointsnp[n][0] = p[0]
pointsnp[n][1] = p[1]
pointsnp[n][2] = p[2]
n += 1
# break
np.savetxt('lidar1.txt', pointsnp, delimiter=' &#