ros中kinect相机sensor_msgs.msg PointCloud2类型点云 转 open3d 点云
python 语言
时间:2023.7.30
代码:
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import rospy
from sensor_msgs.msg import PointCloud2
from sensor_msgs import point_cloud2
import open3d
class PointCloudSubscriber(object):
def __init__(self) -> None:
self.sub = rospy.Subscriber("/kinect_98/kinect2/hd/points",
PointCloud2,
self.callback, queue_size=5)
def callback(self, msg):
assert isinstance(msg, PointCloud2)
points = point_cloud2.read_points(msg,field_names=("x","y","z"))
#points = point_cloud2.read_points_list(
# msg, field_names=("x", "y", "z"))
p = open3d.geometry.PointCloud()
p.points = open3d.utility.Vector3dVector(points)
print(p)
#后续对点云进行各种操作,就用open3d的库函数即可
if __name__ =='__main__':
rospy.init_node("pointcloud_subscriber")
PointCloudSubscriber()
rospy.spin()