一共由三个节点完成
1。pcd文件的读取
我的数据集来自百度开源数据集apolloscape。下载下来是bin格式,转成pcd(之前有写bin转pcd)。
这个是pcd文件读取和显示。
pcl_load.cpp
#include<ros/ros.h>
#include<pcl/point_cloud.h>
#include<pcl_conversions/pcl_conversions.h>
#include<sensor_msgs/PointCloud2.h>
#include<pcl/io/pcd_io.h>//which contains the required definitions to load and store point clouds to PCD and other file formats.
main (int argc, char **argv)
{
ros::init (argc, argv, "UandBdetect");
ros::NodeHandle nh;
ros::Publisher pcl_pub = nh.advertise<sensor_msgs::PointCloud2> ("pcl_output", 1);
pcl::PointCloud<pcl::PointXYZ> cloud;
sensor_msgs::PointCloud2 output;
pcl::io::loadPCDFile ("/home/limengxi/all/1/src/abc/imgpcl.pcd", cloud); //修改自己pcd文件所在路径
//Convert the cloud to ROS message
pcl::toROSMsg(cloud, output);
output.header.frame_id = "odom";//this has been done in order to be able to visualize our PointCloud2 message on the RViz visualizer
//!!!这一步需要注意,是后面rviz的 fixed_frame !!!敲黑板,画重点。
ros::Rate loop_rate(1);
while (ros::ok())
{
pcl_pub.publish(output);
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}
这个需要编译,建立工作空间,source,建立软件包,放入pcl_load.cpp(记得修改package.xml 和 Cmakelist.txt) ,在工作空间编译。
我的软件包名abc 节点名称 abc _node 启动文件名 abc_node.cpp ps:节点名称可在cmakelists.txt 中修改。
output.header.frame_id = "odom";//this has been done in order to be able to visualize our PointCloud2 message on the RViz visualizer
//!!!这一步需要注意,是后面rviz的 fixed_frame !!!敲黑板,画重点。
2。修改pcl_rest_node.cpp
记住订阅的是话题,不是节点!!!很重要!!!
之前订阅的是/velodyne_points, 修改成 abc_node 的输出,/pcl_out.
roscore
roslaunch abc abc_node.launch
roslaunch pcl_test pcl_test.launch
可视化节点
rosrun rqt_graph rqt_graph
可以看到节点abc_node 发布的话题/pcl_output被节点/pcl_test_node订阅.
rviz显示配置
rosrun rviz rviz
添加pointcloud2,修改topic为/filtered_points_ground 或 /filtered_points_no_ground.修改fixed_frame 为odom.(前面有提到)
结果:
这个是去除地面信息的话题.
3.欧几里德聚类.
这个不用修改了,因为节点订阅话题为/filtered_points_no_ground,不变.
roslaunch euclidean_cluster euclidean_cluster.launch
可视化节点发布的信息.
配置rviz
add pointcloud2,topic /filtered_points_no_ground ,add boudingboxarray,topic /detected_bouding_box. fixed_frame odom.
结果:
1步代码来源与csdn其他博主,忘了标记了,不好意思,看见与我联系,著名出处,感谢~2,3步代码来自adamshan大佬,感谢!
仅以此篇记录自己的学习,脑子不好用,忘的快~