ros中kinect相机sensor_msgs.msg PointCloud2类型点云 转 open3d 点云

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()

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ROS Noetic,`sensor_msgs`软件包提供了一个名为`transformPointCloud()`的函数,可以将`sensor_msgs/PointCloud2`消息从一个坐标系换到另一个坐标系。该函数的语法如下: ```python transformPointCloud(target_frame, cloud_in, cloud_out, listener) ``` 其,`target_frame`是要换到的目标坐标系的名称,`cloud_in`是输入的`sensor_msgs/PointCloud2`消息,`cloud_out`是输出的换后的`sensor_msgs/PointCloud2`消息,`listener`是一个`tf.TransformListener`对象,用于获取两个坐标系之间的换关系。 以下是一个例子,演示如何在ROS Noetic使用`transformPointCloud()`函数将一个`sensor_msgs/PointCloud2`消息从`camera_link`坐标系换到`base_link`坐标系: ```python import rospy import tf from sensor_msgs.msg import PointCloud2 from sensor_msgs import point_cloud2 from tf2_sensor_msgs.tf2_sensor_msgs import do_transform_cloud rospy.init_node('transform_point_cloud') listener = tf.TransformListener() cloud_in = rospy.wait_for_message('/camera/depth/color/points', PointCloud2) cloud_out = PointCloud2() transformPointCloud("base_link", cloud_in, cloud_out, listener) # Process the transformed point cloud as desired for p in point_cloud2.read_points(cloud_out, field_names=("x", "y", "z"), skip_nans=True): # Do something with the point cloud data ``` 请注意,`transformPointCloud()`函数的输入和输出都是`sensor_msgs/PointCloud2`消息,因此您需要使用`sensor_msgs.point_cloud2`模块的函数来读取和处理点云数据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值