从一个点云中提取索引

2023-11-06 22:58
文章标签 提取 索引 云中 一个点

本文主要是介绍从一个点云中提取索引,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

附课本代码:

#include <iostream>
#include <pcl/ModelCoefficients.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/sample_consensus/model_types.h>
#include <pcl/segmentation/sac_segmentation.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/filters/extract_indices.h>
int
main (int argc, char** argv)
{sensor_msgs::PointCloud2::Ptr cloud_blob (new sensor_msgs::PointCloud2), cloud_filtered_blob (new sensor_msgs::PointCloud2);pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>), cloud_p (new pcl::PointCloud<pcl::PointXYZ>), cloud_f (new pcl::PointCloud<pcl::PointXYZ>);// 填入点云数据pcl::PCDReader reader;reader.read ("table_scene_lms400.pcd", *cloud_blob);std::cerr << "PointCloud before filtering: " << cloud_blob->width * cloud_blob->height << " data points." << std::endl;// 创建滤波器对象:使用叶大小为1cm的下采样pcl::VoxelGrid<sensor_msgs::PointCloud2> sor;sor.setInputCloud (cloud_blob);sor.setLeafSize (0.01f, 0.01f, 0.01f);sor.filter (*cloud_filtered_blob);// 转化为模板点云pcl::fromROSMsg (*cloud_filtered_blob, *cloud_filtered);std::cerr << "PointCloud after filtering: " << cloud_filtered->width * cloud_filtered->height << " data points." << std::endl;// 将下采样后的数据存入磁盘pcl::PCDWriter writer;writer.write<pcl::PointXYZ> ("table_scene_lms400_downsampled.pcd", *cloud_filtered, false);pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients ());pcl::PointIndices::Ptr inliers (new pcl::PointIndices ());// 创建分割对象pcl::SACSegmentation<pcl::PointXYZ> seg;// 可选seg.setOptimizeCoefficients (true);// 必选seg.setModelType (pcl::SACMODEL_PLANE);seg.setMethodType (pcl::SAC_RANSAC);seg.setMaxIterations (1000);seg.setDistanceThreshold (0.01);// 创建滤波器对象pcl::ExtractIndices<pcl::PointXYZ> extract;int i = 0, nr_points = (int) cloud_filtered->points.size ();// 当还有30%原始点云数据时while (cloud_filtered->points.size () > 0.3 * nr_points){// 从余下的点云中分割最大平面组成部分seg.setInputCloud (cloud_filtered);seg.segment (*inliers, *coefficients);if (inliers->indices.size () == 0){std::cerr << "Could not estimate a planar model for the given dataset." << std::endl;break;}// 分离内层extract.setInputCloud (cloud_filtered);extract.setIndices (inliers);extract.setNegative (false);extract.filter (*cloud_p);std::cerr << "PointCloud representing the planar component: " << cloud_p->width * cloud_p->height << " data points." << std::endl;std::stringstream ss;ss << "table_scene_lms400_plane_" << i << ".pcd";writer.write<pcl::PointXYZ> (ss.str (), *cloud_p, false);// 创建滤波器对象extract.setNegative (true);extract.filter (*cloud_f);cloud_filtered.swap (cloud_f);i++;}return (0);
}



相关对象函数说明:

1、pcl::PointIndices

This is the complete list of members for pcl::PointIndices, including all inherited members.

ConstPtr typedefpcl::PointIndices 
headerpcl::PointIndices 
indicespcl::PointIndices 
PointIndices()pcl::PointIndices 
Ptr typedefpcl::PointIndices

2、SACSegmentation对象

(1)

void pcl::SACSegmentation<PointT >::setOptimizeCoefficients(bool optimize)

Set to true if a coefficient refinement is required.//设置对估计的模型参数进行优化处理

Parameters:
[in]optimizetrue for enabling model coefficient refinement, false otherwise  
(2)
void pcl::SACSegmentation<PointT >::setModelType(int model)

The type of model to use (user given parameter).

Parameters:
[in]modelthe model type
(3)
void pcl::SACSegmentation<PointT >::setMethodType(int method)

The type of sample consensus method to use (user given parameter).

Parameters:
[in]methodthe method type 
    * SAC_RANSAC - RANdom SAmple Consensus
    * SAC_LMEDS - Least Median of Squares
    * SAC_MSAC - M-Estimator SAmple Consensus
    * SAC_RRANSAC - Randomized RANSAC
    * SAC_RMSAC - Randomized MSAC
    * SAC_MLESAC - Maximum LikeLihood Estimation SAmple Consensus
    * SAC_PROSAC - PROgressive SAmple Consensus

(4)
void pcl::SACSegmentation< PointT >::setMaxIterations(int max_iterations)

Set the maximum number of iterations before giving up. 

Parameters:
[in]max_iterationsthe maximum number of iterations the sample consensus method will run  
(5)
void pcl::SACSegmentation< PointT >::setDistanceThreshold(double threshold)

Distance to the model threshold (user given parameter). //设置判断是否为模型内点的距离阈值

Parameters:
[in]thresholdthe distance threshold to use 

(6)

virtual void pcl::PCLBase< PointT >::setInputCloud(const PointCloudConstPtr & cloud)

Provide a pointer to the input dataset.

Parameters:
cloudthe const boost shared pointer to a PointCloud message  
(7)
void pcl::SACSegmentation< PointT >::segment(PointIndices & inliers,
  ModelCoefficients & model_coefficients 
 )

Base method for segmentation of a model in a PointCloud given by <setInputCloud (), setIndices ()>

Parameters:
[in]inliersthe resultant point indices that support the model found (inliers)
[out]model_coefficientsthe resultant model coefficients 
3、ExtractIndices滤波器对象extracts a set of indices from a point cloud.(1)
void pcl::PCLBase< sensor_msgs::PointCloud2 >::setIndices(const PointIndicesConstPtr & indices)

Provide a pointer to the vector of indices that represents the input data.

Parameters:
indicesa pointer to the vector of indices that represents the input data.  

(2)

void pcl::PCLBase< sensor_msgs::PointCloud2 >::setInputCloud(const PointCloud2ConstPtr & cloud) 

Provide a pointer to the input dataset.

Parameters:

cloudthe const boost shared pointer to a PointCloud message

(3)

void pcl::FilterIndices< sensor_msgs::PointCloud2 >::setNegative(bool negative)

Set whether the regular conditions for points filtering should apply, or the inverted conditions.

Parameters:
[in]negativefalse = normal filter behavior (default), true = inverted behavior.
(4)

virtual void pcl::FilterIndices< sensor_msgs::PointCloud2 >::filter(PointCloud2 & output)

Calls the filtering method and returns the filtered dataset in output. 

void pcl::FilterIndices< sensor_msgs::PointCloud2 >::filter(std::vector< int > & indices) 

Calls the filtering method and returns the filtered point cloud indices. 

   

这篇关于从一个点云中提取索引的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/359555

相关文章

使用Python从PPT文档中提取图片和图片信息(如坐标、宽度和高度等)

《使用Python从PPT文档中提取图片和图片信息(如坐标、宽度和高度等)》PPT是一种高效的信息展示工具,广泛应用于教育、商务和设计等多个领域,PPT文档中常常包含丰富的图片内容,这些图片不仅提升了... 目录一、引言二、环境与工具三、python 提取PPT背景图片3.1 提取幻灯片背景图片3.2 提取

C# foreach 循环中获取索引的实现方式

《C#foreach循环中获取索引的实现方式》:本文主要介绍C#foreach循环中获取索引的实现方式,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录一、手动维护索引变量二、LINQ Select + 元组解构三、扩展方法封装索引四、使用 for 循环替代

MySQL索引的优化之LIKE模糊查询功能实现

《MySQL索引的优化之LIKE模糊查询功能实现》:本文主要介绍MySQL索引的优化之LIKE模糊查询功能实现,本文通过示例代码给大家介绍的非常详细,感兴趣的朋友一起看看吧... 目录一、前缀匹配优化二、后缀匹配优化三、中间匹配优化四、覆盖索引优化五、减少查询范围六、避免通配符开头七、使用外部搜索引擎八、分

Python实现word文档内容智能提取以及合成

《Python实现word文档内容智能提取以及合成》这篇文章主要为大家详细介绍了如何使用Python实现从10个左右的docx文档中抽取内容,再调整语言风格后生成新的文档,感兴趣的小伙伴可以了解一下... 目录核心思路技术路径实现步骤阶段一:准备工作阶段二:内容提取 (python 脚本)阶段三:语言风格调

一文详解如何在Python中从字符串中提取部分内容

《一文详解如何在Python中从字符串中提取部分内容》:本文主要介绍如何在Python中从字符串中提取部分内容的相关资料,包括使用正则表达式、Pyparsing库、AST(抽象语法树)、字符串操作... 目录前言解决方案方法一:使用正则表达式方法二:使用 Pyparsing方法三:使用 AST方法四:使用字

详解C#如何提取PDF文档中的图片

《详解C#如何提取PDF文档中的图片》提取图片可以将这些图像资源进行单独保存,方便后续在不同的项目中使用,下面我们就来看看如何使用C#通过代码从PDF文档中提取图片吧... 当 PDF 文件中包含有价值的图片,如艺术画作、设计素材、报告图表等,提取图片可以将这些图像资源进行单独保存,方便后续在不同的项目中使

Python实现常用文本内容提取

《Python实现常用文本内容提取》在日常工作和学习中,我们经常需要从PDF、Word文档中提取文本,本文将介绍如何使用Python编写一个文本内容提取工具,有需要的小伙伴可以参考下... 目录一、引言二、文本内容提取的原理三、文本内容提取的设计四、文本内容提取的实现五、完整代码示例一、引言在日常工作和学

C++字符串提取和分割的多种方法

《C++字符串提取和分割的多种方法》在C++编程中,字符串处理是一个常见的任务,尤其是在需要从字符串中提取特定数据时,本文将详细探讨如何使用C++标准库中的工具来提取和分割字符串,并分析不同方法的适用... 目录1. 字符串提取的基本方法1.1 使用 std::istringstream 和 >> 操作符示

基于Python开发批量提取Excel图片的小工具

《基于Python开发批量提取Excel图片的小工具》这篇文章主要为大家详细介绍了如何使用Python中的openpyxl库开发一个小工具,可以实现批量提取Excel图片,有需要的小伙伴可以参考一下... 目前有一个需求,就是批量读取当前目录下所有文件夹里的Excel文件,去获取出Excel文件中的图片,并

详解如何使用Python提取视频文件中的音频

《详解如何使用Python提取视频文件中的音频》在多媒体处理中,有时我们需要从视频文件中提取音频,本文为大家整理了几种使用Python编程语言提取视频文件中的音频的方法,大家可以根据需要进行选择... 目录引言代码部分方法扩展引言在多媒体处理中,有时我们需要从视频文件中提取音频,以便进一步处理或分析。本文