当前位置: 首页 > article >正文

PCL 将点云的曲率数据保存至txt

目录

一、概述

1.1原理

1.2实现步骤

1.3应用场景

二、代码实现

2.1关键函数

2.1.1 计算点云曲率

2.1.2 将曲率保存到txt文件

2.2完整代码

三、实现效果


PCL点云算法汇总及实战案例汇总的目录地址链接:

PCL点云算法与项目实战案例汇总(长期更新)


一、概述

        在三维点云处理过程中,曲率是重要的几何特征之一。通过PCL库的法向量和曲率估算功能,我们可以计算出点云中每个点的曲率,并将其保存到文本文件(txt)中。本文展示如何计算点云的曲率,并将其结果保存为txt文件。

1.1原理

        点云的曲率是通过邻域内点的几何结构计算出来的。曲率计算公式为:

1.2实现步骤

  1. 加载点云数据:从PCD文件中加载点云。
  2. 计算法向量和曲率:使用 pcl::NormalEstimation 计算点云中的法向量和曲率。
  3. 保存曲率到txt文件:将每个点的曲率保存至txt文件中。

1.3应用场景

  1. 表面特征分析:通过曲率判断表面光滑度、凹凸特征。
  2. 3D建模:曲率可以用来检测物体表面细节,改善模型精度。
  3. 点云配准:在配准过程中,曲率特征有助于识别局部特征,提高配准精度。

二、代码实现

2.1关键函数

2.1.1 计算点云曲率

使用 pcl::NormalEstimation 来计算点云的法向量和曲率。

pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
ne.setInputCloud(cloud);                 // 设置输入点云
ne.setSearchMethod(tree);                 // 设置搜索方法
ne.setKSearch(30);                        // 设置邻域搜索的K近邻数
pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
ne.compute(*normals);                     // 计算法向量和曲率

2.1.2 将曲率保存到txt文件

std::ofstream file;
file.open("curvature_data.txt");
for (size_t i = 0; i < normals->points.size(); ++i)
{
    file << "Point " << i << ": Curvature = " << normals->points[i].curvature << std::endl;
}
file.close();

2.2完整代码

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/features/normal_3d.h>
#include <pcl/search/kdtree.h>
#include <fstream>

int main(int argc, char** argv)
{
    // 1. 读取点云数据
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
    if (pcl::io::loadPCDFile<pcl::PointXYZ>("path_to_your_point_cloud.pcd", *cloud) == -1)
    {
        PCL_ERROR("Couldn't read the PCD file!\n");
        return (-1);
    }

    // 2. 创建Kd树进行邻域搜索
    pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
    pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>);
    ne.setInputCloud(cloud);            // 设置输入点云
    ne.setSearchMethod(tree);           // 设置Kd树搜索
    ne.setKSearch(30);                  // 设置K近邻数

    // 3. 计算法向量和曲率
    pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
    ne.compute(*normals);               // 计算法向量和曲率

    // 4. 将曲率数据保存到txt文件
    std::ofstream file;
    file.open("curvature_data.txt");
    for (size_t i = 0; i < normals->points.size(); ++i)
    {
        file << "Point " << i << ": Curvature = " << normals->points[i].curvature << std::endl;
    }
    file.close();

    std::cout << "Curvature data saved to curvature_data.txt" << std::endl;

    return 0;
}

三、实现效果


http://www.kler.cn/news/339111.html

相关文章:

  • 【AI知识点】内部协变量偏移(Internal Covariate Shift)
  • 1打家劫舍三部曲
  • 10.8 sql语句查询(未知的)
  • 等保测评的转型,对于提升我国网络空间的安全防护水平具有重要意义
  • 初始爬虫11
  • Comfyui segmentAnythingUltra V2报错
  • Chromium 搜索引擎功能浅析c++
  • Android 电源管理各个版本的变动和限制
  • 一个开源可本地部署的英文翻译服务----EnToZhAPI
  • qt登录界面的完善
  • 【CSS in Depth 2 精译_045】7.1 CSS 响应式设计中的移动端优先设计原则(上)
  • Python | Leetcode Python题解之第456题132模式
  • 0-1开发自己的obsidian plugin DAY 8
  • springboot 打包部署jsp页面两种方式war/jar
  • 中文llama3仿openai api实战
  • Python虚拟环境打包
  • 【题解】【模拟】—— [NOIP2013 普及组] 表达式求值
  • 【物流配送中心选址问题】基于改进粒子群算法
  • 回归预测 | Matlab基于SABO-SVR减法平均算法优化支持向量机的数据多输入单输出回归预测
  • 力扣之603.连续空余座位