点云PCL平面检测及删除SampleConsensusModelPerpendicularPlane

代码

#include "pcllib/pcllib.h"
#include <pcl/sample_consensus/sac_model_perpendicular_plane.h>
#include <pcl/common/angles.h>

int main(int argc, char** argv)
{
    pointcloud::Ptr cloud_filtered(new pointcloud);                   
    pointcloud::Ptr scene(new pointcloud);                  
    pcl::io::loadPCDFile("original_data//13.pcd", *scene);
    PCLLib pcluse;
    pcluse.voxelFliter(scene, cloud_filtered);
    pcl::PointIndices::Ptr tmpinliers(new pcl::PointIndices);
    double distance = 50, degree = 60, max = 10000;
    pcl::PointCloud<pcl::PointXYZ>::Ptr Ncloud_ground_plane(new pcl::PointCloud<pcl::PointXYZ>());
    Eigen::VectorXf coefficients;
    pcl::SampleConsensusModelPerpendicularPlane<pcl::PointXYZ>::Ptr model(new pcl::SampleConsensusModelPerpendicularPlane<pcl::PointXYZ>(cloud_filtered));
    model->setAxis(Eigen::Vector3f(0.0, 1.0, 0.0));	//setAxis用于设置所搜索平面垂直的轴
    model->setEpsAngle(pcl::deg2rad(degree));		//setEpsAngle用于设置待检测的平面模型和上述轴的最大角度
    pcl::RandomSampleConsensus<pcl::PointXYZ> ransac(model);
    ransac.setMaxIterations(max);
    ransac.setDistanceThreshold(distance);
    ransac.computeModel();
    ransac.getInliers(tmpinliers->indices);
    ransac.getModelCoefficients(coefficients);
    pcl::ExtractIndices<pcl::PointXYZ> extract;
    extract.setInputCloud(cloud_filtered);
    extract.setIndices(tmpinliers);
    extract.setNegative(true);
    extract.filter(*Ncloud_ground_plane);
    *cloud_filtered = *Ncloud_ground_plane;
    std::cout << "show the data after deleting ground plane!" << endl;
    /*pcl::PCDWriter writer;
    writer.write("downsampled.pcd", *cloud_filtered);*/
    boost::shared_ptr<pcl::visualization::PCLVisualizer> view(new pcl::visualization::PCLVisualizer("fpfh test"));    
    view->setBackgroundColor(0, 0, 0);      
    view->addPointCloud(cloud_filtered, "target_cloud_v1");
    while (!view->wasStopped())
    {
        view->spinOnce(100);    
        pcl_sleep(0.01);
    }

实验结果
在这里插入图片描述

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值