pcl::ExtractPolygonalPrismData类
来源:互联网 发布:淘宝上井江茶油造假 编辑:程序博客网 时间:2024/06/14 18:08
ExtractPolygonalPrismData通过设定处于同一平面模型上的点索引向量,并指定一定高度,利用指定的点形成二维凸包,再结合指定高度一起生成一个多边形棱柱模型,该类用于分割出该棱柱模型的内部点集,比如分割出平面上的物体。下面用一个例子演示其用法。
#include <pcl/io/pcd_io.h>#include <pcl/sample_consensus/method_types.h>#include <pcl/sample_consensus/model_types.h>#include <pcl/segmentation/sac_segmentation.h>#include <pcl/filters/extract_indices.h>#include <pcl/surface/convex_hull.h>#include <pcl/segmentation/extract_polygonal_prism_data.h>#include <pcl/visualization/cloud_viewer.h>#include <iostream>intmain(int argc, char** argv){ pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); pcl::PointCloud<pcl::PointXYZ>::Ptr plane(new pcl::PointCloud<pcl::PointXYZ>); pcl::PointCloud<pcl::PointXYZ>::Ptr convexHull(new pcl::PointCloud<pcl::PointXYZ>); pcl::PointCloud<pcl::PointXYZ>::Ptr objects(new pcl::PointCloud<pcl::PointXYZ>); if (pcl::io::loadPCDFile<pcl::PointXYZ>("table_scene_mug_stereo_textured.pcd", *cloud) != 0) { return -1; } pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients); // 采样一致性算法实现的分割类 pcl::SACSegmentation<pcl::PointXYZ> segmentation; segmentation.setInputCloud(cloud); // 设置构造的几何模型类型 segmentation.setModelType(pcl::SACMODEL_PLANE); // 设置采样一致性方法类型 segmentation.setMethodType(pcl::SAC_RANSAC); // 设置点到模型的距离阈值 segmentation.setDistanceThreshold(0.01); // 设置模型参数优化 segmentation.setOptimizeCoefficients(true); pcl::PointIndices::Ptr planeIndices(new pcl::PointIndices); segmentation.segment(*planeIndices, *coefficients); if (planeIndices->indices.size() == 0) std::cout << "Could not find a plane in the scene." << std::endl; else { // Copy the points of the plane to a new cloud. pcl::ExtractIndices<pcl::PointXYZ> extract; extract.setInputCloud(cloud); extract.setIndices(planeIndices); extract.filter(*plane); // 保存平面点云 pcl::io::savePCDFile("plane.pcd",*plane); // 生成凸包 pcl::ConvexHull<pcl::PointXYZ> hull; hull.setInputCloud(plane); hull.setDimension(2); hull.reconstruct(*convexHull); // 冗余检查. if (hull.getDimension() == 2) { // 该类用于分割出棱柱模型内部的点集 pcl::ExtractPolygonalPrismData<pcl::PointXYZ> prism; prism.setInputCloud(cloud); // 设置平面模型的点集 prism.setInputPlanarHull(convexHull); // 设置高度范围 prism.setHeightLimits(0.01f, 0.4f); pcl::PointIndices::Ptr objectIndices(new pcl::PointIndices); prism.segment(*objectIndices); // Get and show all points retrieved by the hull. extract.setIndices(objectIndices); extract.filter(*objects); pcl::visualization::CloudViewer viewerObjects("Objects on table"); viewerObjects.showCloud(objects); pcl::io::savePCDFile("objects.pcd", *objects); while (!viewerObjects.wasStopped()) { // Do nothing but wait. } } else std::cout << "The chosen hull is not planar." << std::endl; }}
线面是分割的效果图
分割的平面效果图
分割出桌面上的杯子
阅读全文
0 0
- pcl::ExtractPolygonalPrismData类
- 【PCL】非常用类整理
- PCL 记录时间长度 — TicToc 类
- PCL中关于滤波模块的类
- PCL 库中的pcl::visualization::PCLVisualizer类彩色显示点云
- PCL--pcl::copyPointCloud 使用方法
- PCL中IO模块和类的介绍
- PCL学习
- PCL registration
- PCL学习
- PCL配置
- QT + PCL
- PCL入门
- pcl install
- PCL配置
- PCL输入输出
- Pcl配置
- PCL相关
- java-static关键解读
- PYTHON smtp 发送qq邮件
- vue中如何使用less
- Sqrt(x)
- 实现文本域输入字数的限制
- pcl::ExtractPolygonalPrismData类
- keras2 predict和fit_generator的坑
- 应用expect的自动应答
- Add to List 313. Super Ugly Number
- Java8的四大核心函数式接口
- 第一课、java开发环境的安装
- 随机一致性检测RANSAC
- 位操作
- Eclipse用tomcat有事出现的问题