PCL学习笔记——NormalEstimation估计点云的法向量

主要Classes:
pcl::NormalEstimation< PointInT, PointOutT > Class
头文件:
#include

Code:
// overlapped_points_normal_estimation.cpp: 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include

using namespace std;

int main()
{
	pcl::PointCloud::Ptr cloudA(new pcl::PointCloud);
	pcl::PointCloud::Ptr cloudB(new pcl::PointCloud);
	pcl::PointCloud::Ptr overlapA(new pcl::PointCloud);
	pcl::PointCloud::Ptr overlapB(new pcl::PointCloud);


	if (pcl::io::loadPCDFile("pointA.pcd", *cloudA) == -1)
	{
		PCL_ERROR("Couldn't read the pointA.pcd\n");
		return -1;
	}
	if (pcl::io::loadPCDFile("pointB.pcd", *cloudB) == -1)
	{
		PCL_ERROR("Couldn't read the pointB.pcd\n");
		return -1;
	}
	if (pcl::io::loadPCDFile("overlapA.pcd", *overlapA) == -1)
	{
		PCL_ERROR("Couldn't read the pointB.pcd\n");
		return -1;
	}
	if (pcl::io::loadPCDFile("overlapB.pcd", *overlapB) == -1)
	{
		PCL_ERROR("Couldn't read the pointB.pcd\n");
		return -1;
	}
	//创建法线估计对象,并将输入数据集传递给这个对象
	pcl::NormalEstimationne1;
	pcl::NormalEstimationne2;

	ne1.setInputCloud(overlapA);
	ne1.setSearchSurface(cloudA);

	ne2.setInputCloud(overlapB);
	ne2.setSearchSurface(cloudB);

	//以kdtree作为索引方式
	pcl::search::KdTree::Ptr treeA(new pcl::search::KdTree);
	pcl::search::KdTree::Ptr treeB(new pcl::search::KdTree);
    ne1.setSearchMethod(treeA);
	ne1.setSearchMethod(treeB);
	
	//存储输出数据集
	pcl::PointCloud::Ptr overlapA_normals(new pcl::PointCloud);
	pcl::PointCloud::Ptr overlapB_normals(new pcl::PointCloud);
	
	ne1.setRadiusSearch(0.4);
	ne2.setRadiusSearch(0.4);
    
	ne1.compute(*overlapA_normals);
	ne2.compute(*overlapB_normals);

	pcl::io::savePCDFileASCII("overlapA_normals.pcd", *overlapA_normals);
	pcl::io::savePCDFileASCII("overlapB_normals.pcd", *overlapB_normals);
	
	return 0;
}


Result:

PCL学习笔记——NormalEstimation估计点云的法向量_第1张图片

你可能感兴趣的:(PCL学习,PCL学习笔记,PCL)