从一个点云中提取索引

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

相关文章

C#提取PDF表单数据的实现流程

《C#提取PDF表单数据的实现流程》PDF表单是一种常见的数据收集工具,广泛应用于调查问卷、业务合同等场景,凭借出色的跨平台兼容性和标准化特点,PDF表单在各行各业中得到了广泛应用,本文将探讨如何使用... 目录引言使用工具C# 提取多个PDF表单域的数据C# 提取特定PDF表单域的数据引言PDF表单是一

C#实现添加/替换/提取或删除Excel中的图片

《C#实现添加/替换/提取或删除Excel中的图片》在Excel中插入与数据相关的图片,能将关键数据或信息以更直观的方式呈现出来,使文档更加美观,下面我们来看看如何在C#中实现添加/替换/提取或删除E... 在Excandroidel中插入与数据相关的图片,能将关键数据或信息以更直观的方式呈现出来,使文档更

Java后端接口中提取请求头中的Cookie和Token的方法

《Java后端接口中提取请求头中的Cookie和Token的方法》在现代Web开发中,HTTP请求头(Header)是客户端与服务器之间传递信息的重要方式之一,本文将详细介绍如何在Java后端(以Sp... 目录引言1. 背景1.1 什么是 HTTP 请求头?1.2 为什么需要提取请求头?2. 使用 Spr

使用Java解析JSON数据并提取特定字段的实现步骤(以提取mailNo为例)

《使用Java解析JSON数据并提取特定字段的实现步骤(以提取mailNo为例)》在现代软件开发中,处理JSON数据是一项非常常见的任务,无论是从API接口获取数据,还是将数据存储为JSON格式,解析... 目录1. 背景介绍1.1 jsON简介1.2 实际案例2. 准备工作2.1 环境搭建2.1.1 添加

oracle数据库索引失效的问题及解决

《oracle数据库索引失效的问题及解决》本文总结了在Oracle数据库中索引失效的一些常见场景,包括使用isnull、isnotnull、!=、、、函数处理、like前置%查询以及范围索引和等值索引... 目录oracle数据库索引失效问题场景环境索引失效情况及验证结论一结论二结论三结论四结论五总结ora

Python中列表的高级索引技巧分享

《Python中列表的高级索引技巧分享》列表是Python中最常用的数据结构之一,它允许你存储多个元素,并且可以通过索引来访问这些元素,本文将带你深入了解Python列表的高级索引技巧,希望对... 目录1.基本索引2.切片3.负数索引切片4.步长5.多维列表6.列表解析7.切片赋值8.删除元素9.反转列表

MySQL的索引失效的原因实例及解决方案

《MySQL的索引失效的原因实例及解决方案》这篇文章主要讨论了MySQL索引失效的常见原因及其解决方案,它涵盖了数据类型不匹配、隐式转换、函数或表达式、范围查询、LIKE查询、OR条件、全表扫描、索引... 目录1. 数据类型不匹配2. 隐式转换3. 函数或表达式4. 范围查询之后的列5. like 查询6

python解析HTML并提取span标签中的文本

《python解析HTML并提取span标签中的文本》在网页开发和数据抓取过程中,我们经常需要从HTML页面中提取信息,尤其是span元素中的文本,span标签是一个行内元素,通常用于包装一小段文本或... 目录一、安装相关依赖二、html 页面结构三、使用 BeautifulSoup javascript

PostgreSQL如何查询表结构和索引信息

《PostgreSQL如何查询表结构和索引信息》文章介绍了在PostgreSQL中查询表结构和索引信息的几种方法,包括使用`d`元命令、系统数据字典查询以及使用可视化工具DBeaver... 目录前言使用\d元命令查看表字段信息和索引信息通过系统数据字典查询表结构通过系统数据字典查询索引信息查询所有的表名可

性能分析之MySQL索引实战案例

文章目录 一、前言二、准备三、MySQL索引优化四、MySQL 索引知识回顾五、总结 一、前言 在上一讲性能工具之 JProfiler 简单登录案例分析实战中已经发现SQL没有建立索引问题,本文将一起从代码层去分析为什么没有建立索引? 开源ERP项目地址:https://gitee.com/jishenghua/JSH_ERP 二、准备 打开IDEA找到登录请求资源路径位置