从一个点云中提取索引

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

相关文章

MySQL之InnoDB存储引擎中的索引用法及说明

《MySQL之InnoDB存储引擎中的索引用法及说明》:本文主要介绍MySQL之InnoDB存储引擎中的索引用法及说明,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录1、背景2、准备3、正篇【1】存储用户记录的数据页【2】存储目录项记录的数据页【3】聚簇索引【4】二

全面解析MySQL索引长度限制问题与解决方案

《全面解析MySQL索引长度限制问题与解决方案》MySQL对索引长度设限是为了保持高效的数据检索性能,这个限制不是MySQL的缺陷,而是数据库设计中的权衡结果,下面我们就来看看如何解决这一问题吧... 目录引言:为什么会有索引键长度问题?一、问题根源深度解析mysql索引长度限制原理实际场景示例二、五大解决

MySQL中的索引结构和分类实战案例详解

《MySQL中的索引结构和分类实战案例详解》本文详解MySQL索引结构与分类,涵盖B树、B+树、哈希及全文索引,分析其原理与优劣势,并结合实战案例探讨创建、管理及优化技巧,助力提升查询性能,感兴趣的朋... 目录一、索引概述1.1 索引的定义与作用1.2 索引的基本原理二、索引结构详解2.1 B树索引2.2

python3如何找到字典的下标index、获取list中指定元素的位置索引

《python3如何找到字典的下标index、获取list中指定元素的位置索引》:本文主要介绍python3如何找到字典的下标index、获取list中指定元素的位置索引问题,具有很好的参考价值,... 目录enumerate()找到字典的下标 index获取list中指定元素的位置索引总结enumerat

从入门到精通MySQL 数据库索引(实战案例)

《从入门到精通MySQL数据库索引(实战案例)》索引是数据库的目录,提升查询速度,主要类型包括BTree、Hash、全文、空间索引,需根据场景选择,建议用于高频查询、关联字段、排序等,避免重复率高或... 目录一、索引是什么?能干嘛?核心作用:二、索引的 4 种主要类型(附通俗例子)1. BTree 索引(

Python中提取文件名扩展名的多种方法实现

《Python中提取文件名扩展名的多种方法实现》在Python编程中,经常会遇到需要从文件名中提取扩展名的场景,Python提供了多种方法来实现这一功能,不同方法适用于不同的场景和需求,包括os.pa... 目录技术背景实现步骤方法一:使用os.path.splitext方法二:使用pathlib模块方法三

Python实现精准提取 PDF中的文本,表格与图片

《Python实现精准提取PDF中的文本,表格与图片》在实际的系统开发中,处理PDF文件不仅限于读取整页文本,还有提取文档中的表格数据,图片或特定区域的内容,下面我们来看看如何使用Python实... 目录安装 python 库提取 PDF 文本内容:获取整页文本与指定区域内容获取页面上的所有文本内容获取

C/C++的OpenCV 进行图像梯度提取的几种实现

《C/C++的OpenCV进行图像梯度提取的几种实现》本文主要介绍了C/C++的OpenCV进行图像梯度提取的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的... 目录预www.chinasem.cn备知识1. 图像加载与预处理2. Sobel 算子计算 X 和 Y

MySQL 添加索引5种方式示例详解(实用sql代码)

《MySQL添加索引5种方式示例详解(实用sql代码)》在MySQL数据库中添加索引可以帮助提高查询性能,尤其是在数据量大的表中,下面给大家分享MySQL添加索引5种方式示例详解(实用sql代码),... 在mysql数据库中添加索引可以帮助提高查询性能,尤其是在数据量大的表中。索引可以在创建表时定义,也可

Python对PDF书签进行添加,修改提取和删除操作

《Python对PDF书签进行添加,修改提取和删除操作》PDF书签是PDF文件中的导航工具,通常包含一个标题和一个跳转位置,本教程将详细介绍如何使用Python对PDF文件中的书签进行操作... 目录简介使用工具python 向 PDF 添加书签添加书签添加嵌套书签Python 修改 PDF 书签Pytho