• PCL智能指针疑云 <二> 使用同一智能指针作为PCL预处理API的输入和输出


    问题介绍

    slam构建地图,先进行降采样,再进行可视化或存储。然而经过降采样后,代码没有报错的情况下,点云数据散成一团。将代码和点云数据展示如下,

    pcl::VoxelGrid<Lidar::PointType> voxel_filter;
    voxel_filter.setLeafSize(0.02, 0.02, 0.02);
    
    Lidar::PointCloudPtr mapPointCloud(new Lidar::PointCloudType); //滤波器输入变量
    //...
    //往输入变量中填充数据
    //...
    
    voxel_filter.setInputCloud(mapPointCloud);
    voxel_filter.filter(*mapPointCloud);
    std::cout << "after voxel_filter, mapPointCloud size : " << mapPointCloud->points.size() << std::endl;
    std::string index = std::to_string(ndtCount);
    pcl::io::savePCDFileASCII ("/home/gordon/fase_ws/src/ddd_wall_mapping/filter_map_"+index+".pcd",
                                   *mapPointCloud);

    问题分析

    猜想是由于降采样滤波器的输入和输出是同一个指针变量,在处理过程中内存混乱,导致点云数据出错。

    解决方案

    使用两个不同的变量作为降采样滤波器的输入和输出,并且作为输出的变量每次都要进行清空操作。

    问题解决后的代码和点云数据展示如下,

    pcl::VoxelGrid<Lidar::PointType> voxel_filter;
    voxel_filter.setLeafSize(0.02, 0.02, 0.02);
    
    Lidar::PointCloudPtr mapPointCloud(new Lidar::PointCloudType); //滤波器输入变量
    //...
    //往输入变量中填充数据
    //...
    
    Lidar::PointCloudPtr filter_mapPointCloud(new Lidar::PointCloudType); // 滤波器输出变量
    voxel_filter.setInputCloud(mapPointCloud);
    voxel_filter.filter(*filter_mapPointCloud);
    mapPointCloud->clear();
    *mapPointCloud += *filter_mapPointCloud;
    std::cout << "after voxel_filter, mapPointCloud size : " << mapPointCloud->points.size() << std::endl;
    std::string index = std::to_string(ndtCount);
    pcl::io::savePCDFileASCII ("/home/gordon/fase_ws/src/ddd_wall_mapping/filter_map_"+index+".pcd", *mapPointCloud);

    至于具体原因,至今不详,忘高手或前辈指点迷津。 

  • 相关阅读:
    xpath解析以及lxml解析库
    python sort()和sorted()的不同
    爬取电影天堂-二级页面抓取
    爬取猫眼电影榜单TOP100榜-以mysql数据库保存
    爬取猫眼电影榜单TOP100榜-以csv文件保存
    爬取猫眼电影榜单TOP100榜-以命令行输出
    爬虫 贪婪匹配以及非贪婪匹配
    爬取百度贴吧
    python 面试
    python 从array保存伪色彩图片 —— 发现的坑
  • 原文地址:https://www.cnblogs.com/gdut-gordon/p/10942776.html
Copyright © 2020-2023  润新知