《QT+PCL第七章》点云分割-多平面分割(结合CGAL)

51 篇文章 715 订阅 ¥19.90 ¥99.00

前言

本节主要将CGAL中RANSAC方法的平面分割功能添加到QT软件中。

一、效果展示

在这里插入图片描述

二、核心代码

1、核心代码:难点在于将分割好的点云提取

    Efficient_ransac ransac;
    ransac.set_input(cgal_cloud);
    ransac.
  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
返回这个容器。 首先,我们需要使用PCL库的SACSegmentation算法将每个点云分割成一个平面。然后,我们可以使用PCL的ExtractIndices算法来提取每个平面点云,并将它们存储在一个容器。最后,我们可以使用PCL的Intersection算法来检测这些平面是否相交,并提取相交处的点云。 下面是一个简单的示例代码,用于检测两个平面点云是否相交: ``` #include <pcl/point_types.h> #include <pcl/io/pcd_io.h> #include <pcl/filters/extract_indices.h> #include <pcl/sample_consensus/method_types.h> #include <pcl/sample_consensus/model_types.h> #include <pcl/segmentation/sac_segmentation.h> #include <pcl/segmentation/extract_clusters.h> #include <pcl/common/geometry.h> typedef pcl::PointXYZ PointT; int main(int argc, char** argv) { // Load point clouds from file pcl::PointCloud<PointT>::Ptr cloud1(new pcl::PointCloud<PointT>); pcl::PointCloud<PointT>::Ptr cloud2(new pcl::PointCloud<PointT>); pcl::io::loadPCDFile<PointT>("cloud1.pcd", *cloud1); pcl::io::loadPCDFile<PointT>("cloud2.pcd", *cloud2); // Segment planes in each point cloud pcl::ModelCoefficients::Ptr coefficients1(new pcl::ModelCoefficients); pcl::PointIndices::Ptr inliers1(new pcl::PointIndices); pcl::SACSegmentation<PointT> seg1; seg1.setOptimizeCoefficients(true); seg1.setModelType(pcl::SACMODEL_PLANE); seg1.setMethodType(pcl::SAC_RANSAC); seg1.setDistanceThreshold(0.01); seg1.setInputCloud(cloud1); seg1.segment(*inliers1, *coefficients1); pcl::ModelCoefficients::Ptr coefficients2(new pcl::ModelCoefficients); pcl::PointIndices::Ptr inliers2(new pcl::PointIndices); pcl::SACSegmentation<PointT> seg2; seg2.setOptimizeCoefficients(true); seg2.setModelType(pcl::SACMODEL_PLANE); seg2.setMethodType(pcl::SAC_RANSAC); seg2.setDistanceThreshold(0.01); seg2.setInputCloud(cloud2); seg2.segment(*inliers2, *coefficients2); // Extract plane point clouds pcl::PointCloud<PointT>::Ptr plane1(new pcl::PointCloud<PointT>); pcl::PointCloud<PointT>::Ptr plane2(new pcl::PointCloud<PointT>); pcl::ExtractIndices<PointT> extract1; extract1.setInputCloud(cloud1); extract1.setIndices(inliers1); extract1.filter(*plane1); pcl::ExtractIndices<PointT> extract2; extract2.setInputCloud(cloud2); extract2.setIndices(inliers2); extract2.filter(*plane2); // Compute intersection of planes Eigen::Vector4f plane1_coeffs(coefficients1->values.data()); Eigen::Vector4f plane2_coeffs(coefficients2->values.data()); Eigen::Vector3f plane1_normal(plane1_coeffs.head<3>()); Eigen::Vector3f plane2_normal(plane2_coeffs.head<3>()); Eigen::Vector3f intersection_pt; pcl::planeWithPlaneIntersection(plane1_normal, plane2_normal, intersection_pt); // Extract points at intersection pcl::PointCloud<PointT>::Ptr intersection(new pcl::PointCloud<PointT>); pcl::ExtractIndices<PointT> extract3; extract3.setInputCloud(cloud1); extract3.setIndices(inliers1); extract3.setNegative(true); extract3.filter(*intersection); pcl::ExtractIndices<PointT> extract4; extract4.setInputCloud(cloud2); extract4.setIndices(inliers2); extract4.setNegative(true); extract4.filter(*intersection); // Output intersection point cloud pcl::io::savePCDFileASCII("intersection.pcd", *intersection); return 0; } ``` 这个示例代码假设我们有两个点云文件"cloud1.pcd"和"cloud2.pcd",并使用SACSegmentation算法将每个点云分割成一个平面。然后,我们使用ExtractIndices算法提取每个平面点云,并将它们存储在plane1和plane2。接下来,我们计算两个平面的交点,并使用ExtractIndices算法提取相交处的点云,并将它们存储在intersection。最后,我们将intersection点云保存到文件"intersection.pcd"

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小修勾

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值