PCL ProjectInliers 投影滤波器

一、原理

将点投影到一个参数化模型上,这个参数化模型可以是平面、圆球、圆柱、锥形等进行投影滤波。

二、代码显示

 重点代码 

  
     //  我们的想法是创建一个平面  ax+by+cz+d=0; c!=0
    pcl::ModelCoefficients::Ptr c(new  pcl::ModelCoefficients());
    c->values.resize(4);  //ax + by + cz + d = 0
    c->values[0] = 1.0;  // ax 
    c->values[1] = 1.0;// by
    c->values[2] = 1.0;  //cz 
    c->values[3] = 0;//d 


     // 开始投影滤波
    pcl::ProjectInliers<pcl::PointXYZ> pro;   // 定义一个投影对象
    pro.setInputCloud(cloud);  
    pro.setModelType(pcl::SACMODEL_PLANE);  // 平面作为投影的模型
    pro.setModelCoefficients(c);  // 系数
    pro.filter(*cloud_filtered);
 

整体代码: 


#if 1  //   投影滤波
using namespace std;
int main()
{
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);			//待滤波点云
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>);	//滤波后点云

    ///读入点云数据
    cout << "->正在读入点云..." << endl;
    pcl::PCDReader reader;
    reader.read("desktop.pcd", *cloud);
    cout << "\t\t<读入点云信息>\n" << *cloud << endl;

  
     //  我们的想法是创建一个平面  ax+by+cz+d=0; c!=0
    pcl::ModelCoefficients::Ptr c(new  pcl::ModelCoefficients());
    c->values.resize(4);  //ax + by + cz + d = 0
    c->values[0] = 1.0;  // ax 
    c->values[1] = 1.0;// by
    c->values[2] = 1.0;  //cz 
    c->values[3] = 0;//d 


     // 开始投影滤波
    pcl::ProjectInliers<pcl::PointXYZ> pro;   // 定义一个投影对象
    pro.setInputCloud(cloud);  
    pro.setModelType(pcl::SACMODEL_PLANE);  // 平面作为投影的模型
    pro.setModelCoefficients(c);  // 系数
    pro.filter(*cloud_filtered);
 

    //================================= 滤波前后对比可视化 ================================= ↓

    pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer("滤波前后对比"));

    /*-----视口1-----*/
    int v1(0);
    viewer->createViewPort(0.0, 0.0, 0.5, 1.0, v1); //设置第一个视口在X轴、Y轴的最小值、最大值,取值在0-1之间
    viewer->setBackgroundColor(0, 0, 0, v1); //设置背景颜色,0-1,默认黑色(0,0,0)
    viewer->addText("befor_filtered", 10, 10, "v1_text", v1);
    viewer->addPointCloud<pcl::PointXYZ>(cloud, "befor_filtered_cloud", v1);

    /*-----视口2-----*/
    int v2(0);
    viewer->createViewPort(0.5, 0.0, 1.0, 1.0, v2);
    viewer->setBackgroundColor(0.3, 0.3, 0.3, v2);
    viewer->addText("after_filtered", 10, 10, "v2_text", v2);
    viewer->addPointCloud<pcl::PointXYZ>(cloud_filtered, "after_filtered_cloud", v2);

    /*-----设置相关属性-----*/
    viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "befor_filtered_cloud", v1);
    viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 1, 0, 0, "befor_filtered_cloud", v1);

    viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "after_filtered_cloud", v2);
    viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 0, 1, 0, "after_filtered_cloud", v2);

    while (!viewer->wasStopped())
    {
        viewer->spinOnce(100);
        boost::this_thread::sleep(boost::posix_time::microseconds(100000));
    }

    //================================= 滤波前后对比可视化 ================================= ↑

    return 0;
}

#endif

PCL:投影滤波(二)将点云投影至球面_孙 悟 空的博客-CSDN博客_pcl投影滤波

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值