ROS kinetic环境使用Realsense D435i获取三维点云并存为.pcd文件

  • 使用的环境为ubuntu16.04,AMD64。配置arm架构工控机环境的话,最好另外找资源。

二进制安装D435的SDK

下载intel Realsense ROS工作空间

  • 下载的版本号需要与intel Realsense SDK的版本号对应
  • 下载链接:版本说明及下载。找到Assets点击source code下载工作空间。
  • 通过realsense-viewer查看SDK的版本号,终端输入以下指令,启动可视化软件,比如我的软件左上角为intel realsense viewer V 2.43.0,表示版本号为2.43.0(具体版本号需要自己去查看)。
realsense-viewer
  • 下载的source code放到home目录下的catkin_realsense中,若没有则自己新建。
  • 注意:当编译工作空间不通过时,若提示缺少ddynamic-reconfigur,可通过以下方式安装
 sudo apt install ros-kinetic-ddynamic-reconfigure

ROS下驱动D435i获得点云

  • 编译完工作空间以后,需要将环境环境加入到**.bashrc**文件中。
echo "source ~/catkin_realsense/devel/setup.bash" >> ~/.bashrc	
  • 启动前需要安装rgbd-launch。
sudo apt install ros-kinetic-rgbd-launch
  • 启动相机发布点云话题
roslaunch realsense2_camera rs_rgbd.launch

订阅点云话题并保存为.pcd文件

  • 订阅 /camera/depth_registered/points话题的信息,拿来后处理就行
#include <ros/ros.h>
// PCL specific includes
#include <sensor_msgs/PointCloud2.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
//添加
#include <pcl/PCLPointCloud2.h>
#include <pcl/filters/voxel_grid.h>
#include <iostream>

using namespace std;
 
ros::Publisher pub;
 

void cloud_cb (const sensor_msgs::PointCloud2ConstPtr& cloud_msg)
{
  // Container for original & filtered data
  pcl::PCLPointCloud2* cloud = new pcl::PCLPointCloud2; 
  pcl::PCLPointCloud2ConstPtr cloudPtr(cloud);
  pcl::PCLPointCloud2 cloud_filtered;
  //相机获得原始点云文件
  pcl::io::savePCDFile("./pointcloud_init.pcd", *cloud_msg);
  cout<<"publish point_cloud height = "<<cloud_msg->height<<endl;
  cout<<"publish point_cloud width = "<<cloud_msg->width<<endl;
}
 

int main (int argc, char** argv)
{
  // Initialize ROS
  ros::init (argc, argv, "VoxelGrid");
  ros::NodeHandle nh;
 
  // Create a ROS subscriber for the input point cloud
  ros::Subscriber sub = nh.subscribe<sensor_msgs::PointCloud2> ("/camera/depth_registered/points", 1, cloud_cb);
 
  // Spin
  ros::spin ();
}

使用plc_tool查看pcd文件

  • 安装pcl_tool
sudo apt install pcl-tools
  • 终端输入以下指令,查看xxx.pcd文件,xxx为自己的文件名
pcl_viewer xxx.pcd

我的工作空间和代码更新链接

  • 我的相机驱动工作空间代码对应SDK的版本为2.43.0。
  • 代码github
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值