激光雷达点云数据处理

步骤:

1. 通过rosbag录制激光雷达数据

2. 将rosbag转为pcd格式,一帧一个文件

3. 解析pcd文件数据

 

详细步骤

  1. 使用速腾16线激光雷达
    1. cd到激光雷达程序目录,运行launch文件
    2. rostopic list 查看topic信息,然后rosbag record /rslidar_points,会在对应目录下生成一个以时间命名的文件,里面记录 的激光雷达点云数据,链接:http://wiki.ros.org/ROS/Tutorials/Recording%20and%20playing%20back%20data
  2. 通过以下命令来将rosbag转换为pcd

    rosrun pcl_ros bag_to_pcd Desktop/2018-10-10-14-19-26.bag /rslidar_points Desktop/pcd

                                                      rosbag路径                                      需要转换的topic  pcd文件存储路径

  3. 通过以下代码将pcd文件解析出来,并且通过pcl viewer将那一帧的点云数据可视化

    #include  
    #include  
    #include  
    #include  
    #include  
    using namespace std; 
    
    int main (int argc, char** argv){ 
    typedef pcl::PointXYZRGBA PointT; 
    pcl::PointCloud::Ptr cloud (new pcl::PointCloud); 
    
    std::string dir = "/home/deanjin/Desktop/pcd/"; 
    std::string filename = "1539152366.934292000.pcd"; 
    
    if (pcl::io::loadPCDFile ((dir+filename), *cloud) == -1){ 
    //* load the file 
    PCL_ERROR ("Couldn't read PCD file \n"); 
    return (-1); 
    } 
    printf("Loaded %d data points from PCD\n", 
    cloud->width * cloud->height); 
    
    printf("points size is %ld\n", cloud->points.size());
    
    for (size_t i = 0; i < cloud->points.size (); i+=10000) 
    printf("%8.3f %8.3f %8.3f %5d %5d %5d %5d\n", 
    cloud->points[i].x, 
    cloud->points[i].y, 
    cloud->points[i].z, 
    cloud->points[i].r, 
    cloud->points[i].g, 
    cloud->points[i].b, 
    cloud->points[i].a 
    ); 
    
    pcl::visualization::PCLVisualizer viewer("Cloud viewer"); 
    viewer.setCameraPosition(0,0,-3.0,0,-1,0); 
    viewer.addCoordinateSystem(0.3); 
    
    viewer.addPointCloud(cloud); 
    while(!viewer.wasStopped()) 
    viewer.spinOnce(100); 
    return (0); 
    } 

    CmakeList.txt

    cmake_minimum_required(VERSION 2.8.3)
    project(test)
    find_package(PCL REQUIRED) 
    include_directories(${PCL_INCLUDE_DIRS}) 
    add_executable(test test.cpp)
    target_link_libraries(test ${PCL_LIBRARIES}) 

     

你可能感兴趣的:(学习笔记)