PCL点云之旅10 - 体素滤波

930 阅读1分钟

什么是体素滤波

体素滤波器是一种下采样的滤波器,它的作用是使用体素化方法减少点云数量,采用体素格中接近中心点的点替代体素内的所有点云,这种方法比直接使用中心点要慢,但是更加精确。这种方式即减少点云数据,并同时保存点云的形状特征,在提高配准,曲面重建,形状识别等算法速度中非常实用。

可以使用pcl_viewer查看原图和体素滤波之后的效果,从输出结果和图片对比,都可以看出点云数量明显变少,但是轮廓没有发生改变。

实现效果

image.png

image.png

image.png

步骤拆分

  1. 首先编写槽函数
  2. 导入点云
  3. 编写体素滤波算法
  4. 传入参数实现算法

代码实现

image.png

// 滤波
void MainWindow::voxel_filter_press(){
    dialog_voxel=new voxel_filter_dialog();
    connect(dialog_voxel,SIGNAL(sendData(QString)),this,SLOT(voxel_clicked(QString)));
    if(dialog_voxel->exec()==QDialog::Accepted){}
    delete dialog_voxel;
}



void MainWindow::voxel_clicked(QString data){
    if(cloud.empty()){
        QMessageBox::warning(this,"warning","无点云输入");
        return;
    }else{
        std::cout<<"滤波大小为:"+data.toStdString()<<std::endl;
        if(data.isEmpty()){
            QMessageBox::warning(this,"warning","参数格式错误");
            return ;
        }
        float size=data.toFloat();
        auto cloud_out=pcl_filter_voxel(cloud.makeShared(),size);
        cloud = *cloud_out;
        int size1 = static_cast<int>(cloud.size());
        QString PointSize = QString("%1").arg(size1);
        viewer->removeAllPointClouds();
        viewer->removeAllShapes();
        viewer->addPointCloud(cloud.makeShared() ,cloud_name[0]);
        viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, point_size, cloud_name[0]);
        viewer->resetCamera();
        ui->qvtkWidget->update();
    }
}