码迷,mamicode.com
首页 > 其他好文 > 详细

基于八叉树的动态障碍物滤出

时间:2021-06-02 12:48:57      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:sid   inf   ant   buffer   范围   keep   std   data   tin   

话不多说直接上代码

#include <pcl/point_cloud.h>
#include <pcl/octree/octree_pointcloud_changedetector.h>

#include <iostream>
#include <vector>
#include <ctime>

pcl::PointCloud<pcl::PointXYZI>::Ptr dynamic_obj_detec(pcl::PointCloud<pcl::PointXYZI>::Ptr cloud_before, pcl::PointCloud<pcl::PointXYZI>::Ptr cloud_now){
    std::cout<<"has data "<<cloud_now->size()<<"  "<<cloud_before->size()<<std::endl;
    pcl::PointCloud<pcl::PointXYZI>::Ptr cloud_fliter(new pcl::PointCloud<pcl::PointXYZI>());
    srand((unsigned int) time (NULL));

    // Octree resolution - side length of octree voxels
    float resolution = 0.2f;//20cm范围内如果前后两帧占用概率变换则认为是动态障碍物

    // Instantiate octree-based point cloud change detection class
    pcl::octree::OctreePointCloudChangeDetector<pcl::PointXYZI> octree (resolution);

    // Add points from cloudA to octree
    octree.setInputCloud (cloud_before);
    octree.addPointsFromInputCloud ();

    // Switch octree buffers: This resets octree but keeps previous tree structure in memory.
    //交换八叉树缓存,但是cloudA对应的八叉树结构仍在内存中
    octree.switchBuffers ();

    // Add points from cloudB to octree
    octree.setInputCloud (cloud_now);
    octree.addPointsFromInputCloud ();

    std::vector<int> newPointIdxVector;

    // Get vector of point indices from octree voxels which did not exist in previous buffer
    octree.getPointIndicesFromNewVoxels (newPointIdxVector);

    // Output points
    std::cout << "Output from getPointIndicesFromNewVoxels:" << std::endl;
    std::cout<<newPointIdxVector.size()<<std::endl;
    for (std::size_t i = 0; i < newPointIdxVector.size (); ++i){
        cloud_now->points[newPointIdxVector[i]] = NULL;
    }
    std::cout << "Output from getPointIndicesFromNewVoxels:" << std::endl;
    return cloud_now;
}

技术图片

技术图片
第一张为滤除后的效果,第二张为未滤除的

基于八叉树的动态障碍物滤出

标签:sid   inf   ant   buffer   范围   keep   std   data   tin   

原文地址:https://www.cnblogs.com/chenlinchong/p/14817175.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!