PCL(点云库)学习(一)

最近在学习SLAM(同时定位与地图构建),因此顺带学习了一下,PCL(Point Cloud Library,点云库)。

使用的操作系统为ROS(机器人操作系统),由于ROS集成了opencv和pcl,所以直接运行了PCL的示例代码。

下面是运行步骤、示例代码以及运行结果:

运行步骤:

cd到catkin_ws/src目录下

cd catkin_ws/src

创建package

catkin_create_pkg chapter6_tutorials pcl_conversions pcl_ros pcl_msgs sensor_msgs

cd到chapter6_tutorials目录下

cd chapter6_tutorials

创建src目录并cd到该目录下

mkdir src

cd src

扫描二维码关注公众号,回复: 2139495 查看本文章

创建pcl_sample.cpp文件,并输入如下代码

gedit pcl_sample.cpp

#include<ros/ros.h>
#include<pcl/point_cloud.h>
#include<pcl_ros/point_cloud.h>
#include<pcl_conversions/pcl_conversions.h>
#include<sensor_msgs/PointCloud2.h>


int main(int argc,char** argv)
{
ros::init(argc,argv,"pcl_sample");
ros::NodeHandle nh;
ros::Publisher pcl_pub = nh.advertise<sensor_msgs::PointCloud2>("pcl_output",1);
sensor_msgs::PointCloud2 output;
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
cloud->width = 100;
cloud->height= 1;
cloud->points.resize(cloud->width*cloud->height);

pcl::toROSMsg(*cloud,output);


pcl_pub.publish(output);
ros::spinOnce();
return 0;
}

打开chapter6_tutorials目录下的CMakelist.txt,并增加如下内容:

寻找系统里面的PCL库

find_package(PCL REQUIRED)
include_directories(include ${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS}

生成可执行文件和链接相应的库

add_executable(pcl_sample src/pcl_sample.cpp)
target_link_libraries(pcl_sample ${catkin_LIBRARIES} ${PCL_LIBRARIES})

到 catkin_ws目录下,

运行catkin_make

打开新的终端:

运行 roscore

注册程序

source ./devel/setup.bash

运行节点

rosrun chapter6_tutorials pcl_sample

以上就是运行pcl的过程。

猜你喜欢

转载自blog.csdn.net/github_39611196/article/details/80959591
今日推荐