PCL:点云的法线估计(并显示)

本文通过一个C++示例程序介绍了如何使用PCL库进行点云的法线估计。示例中加载了一个点云文件,并利用PCL库中的NormalEstimation类计算每个点的法线。此外,还展示了如何通过PCLVisualizer可视化原始点云及其对应的法线。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <iostream>
#include <pcl/point_types.h>
#include <pcl/features/normal_3d.h>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>

int main(int argc, char **argv) 
{
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
    pcl::io::loadPCDFile("../table_scene_lms400.pcd", *cloud);

    //create the normal estimation class, and pass the input dataset to it
    pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
    ne.setInputCloud(cloud);

    //create an empty kdtree representation, and pass it to the normal estimation object
    //its content will be filled inside the object, based on the given input dataset(as no other search surface is given)
    pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>());
    ne.setSearchMethod(tree);

    //Output datasets
    pcl::PointCloud<pcl::Normal>::Ptr cloud_normals (new pcl::PointCloud<pcl::Normal>);

    //use all neighbours in a sphere of radius 3cm
    ne.setRadiusSearch(0.03);

    //compute the features
    //cloud_normals->points.size() should have the same size as the input cloud->points.size
    ne.compute(*cloud_normals);

    //normal visualization
    pcl::visualization::PCLVisualizer viewer("PCL viewer");
    viewer.setBackgroundColor(0.0, 0.0, 0.0);
    viewer.addPointCloudNormals<pcl::PointXYZ, pcl::Normal>(cloud, cloud_normals);

    while(!viewer.wasStopped())
    {
      viewer.spinOnce();
    }

    return 0;
}

最终的显示,这个可能还不是很直观

这里写图片描述

这个就比较明显了,红色是原来的点云,白色的是计算的法线,这里就做了个稀疏显示,全部显示效果不是很好。

这里写图片描述

参考地址:
http://www.pointclouds.org/documentation/tutorials/normal_estimation.php#normal-estimation

评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值