其他分享
首页 > 其他分享> > 基于八叉树的动态障碍物滤出

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

作者:互联网

话不多说直接上代码

#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;
}

滤除

未滤除
第一张为滤除后的效果,第二张为未滤除的

标签:std,障碍物,八叉树,滤出,pcl,octree,include,Ptr,cloud
来源: https://www.cnblogs.com/chenlinchong/p/14817175.html