[PCL]2 点云法向量计算NormalEstimation
template <typename PointInT, typename PointOutT> void pcl::Feature<PointInT, PointOutT>::compute (PointCloudOut &output)
{
if (!initCompute ())
{
output.width = output.height = ;
output.points.clear ();
return;
}
// Copy the header
output.header = input_->header;
// Resize the output dataset
if (output.points.size () != indices_->size ())
output.points.resize (indices_->size ());
// Check if the output will be computed for all points or only a subset
// If the input width or height are not set, set output width as size
if (indices_->size () != input_->points.size () || input_->width * input_->height == )
{
output.width = static_cast<uint32_t> (indices_->size ());
output.height = ;
}
else
{
output.width = input_->width;
output.height = input_->height;
}
output.is_dense = input_->is_dense;
// Perform the actual feature computation
computeFeature (output);
deinitCompute ();
}
2.注意computeFeature (output);方法 ,可以知道这是一个私有的虚方法。
template <typename PointInT, typename PointOutT> void pcl::NormalEstimation<PointInT, PointOutT>::computeFeature (PointCloudOut &output)
{
// Allocate enough space to hold the results
// \note This resize is irrelevant for a radiusSearch ().
std::vector< int> nn_indices (k_);
std::vector< float> nn_dists (k_);
output.is_dense = true;
// Save a few cycles by not checking every point for NaN/Inf values if the cloud is set to dense
if (input_->is_dense)
{
// Iterating over the entire index vector
for (size_t idx = ; idx < indices_->size (); ++idx)
{
if (this ->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == ||
!computePointNormal (*surface_, nn_indices, output.points[idx].normal[], output.points[idx].normal[], output.points[idx].normal[], output.points[idx].curvature))
{
output.points[idx].normal[] = output.points[idx].normal[] = output.points[idx].normal[] = output.points[idx].curvature = std::numeric_limits<float >::quiet_NaN ();
output.is_dense = false;
continue;
} flipNormalTowardsViewpoint (input_->points[(*indices_)[idx]], vpx_, vpy_, vpz_, output.points[idx].normal[], output.points[idx].normal[], output.points[idx].normal[]);
}
}
else
{
// Iterating over the entire index vector
for (size_t idx = ; idx < indices_->size (); ++idx)
{
if (!isFinite ((*input_)[(*indices_)[idx]]) ||
this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == ||
!computePointNormal (*surface_, nn_indices, output.points[idx].normal[], output.points[idx].normal[], output.points[idx].normal[], output.points[idx].curvature))
{
output.points[idx].normal[] = output.points[idx].normal[] = output.points[idx].normal[] = output.points[idx].curvature = std::numeric_limits<float >::quiet_NaN (); output.is_dense = false;
continue;
}
flipNormalTowardsViewpoint (input_->points[(*indices_)[idx]], vpx_, vpy_, vpz_, output.points[idx].normal[], output.points[idx].normal[], output.points[idx].normal[]);
}
}
}
4.因此分析NormalEstimation的算法流程如下:

inline bool computePointNormal (const pcl::PointCloud<PointInT> &cloud, const std::vector<int> &indices,
float &nx, float &ny, float &nz, float &curvature)
{
if (indices.size () < ||
computeMeanAndCovarianceMatrix (cloud, indices, covariance_matrix_, xyz_centroid_) == )
{
nx = ny = nz = curvature = std::numeric_limits<float>::quiet_NaN ();
return false;
} // Get the plane normal and surface curvature
solvePlaneParameters (covariance_matrix_, nx, ny, nz, curvature);
return true;
}
computeMeanAndCovarianceMatrix主要是PCA过程中计算平均值和协方差矩阵,在类centroid.hpp中。
而solvePlaneParameters方法则是为了求解特征值和特征向量。代码见feature.hpp。具体实现时采用了pcl::eigen33方法。
inline void pcl::solvePlaneParameters (const Eigen::Matrix3f &covariance_matrix,
float &nx, float &ny, float &nz, float &curvature)
{
// Avoid getting hung on Eigen's optimizers
// for (int i = 0; i < 9; ++i)
// if (!pcl_isfinite (covariance_matrix.coeff (i)))
// {
// //PCL_WARN ("[pcl::solvePlaneParameteres] Covariance matrix has NaN/Inf values!\n");
// nx = ny = nz = curvature = std::numeric_limits<float>::quiet_NaN ();
// return;
// }
// Extract the smallest eigenvalue and its eigenvector
EIGEN_ALIGN16 Eigen::Vector3f::Scalar eigen_value;
EIGEN_ALIGN16 Eigen::Vector3f eigen_vector;
pcl::eigen33 (covariance_matrix, eigen_value, eigen_vector);
nx = eigen_vector [];
ny = eigen_vector [];
nz = eigen_vector []; // Compute the curvature surface change
float eig_sum = covariance_matrix.coeff () + covariance_matrix.coeff () + covariance_matrix.coeff ();
if (eig_sum != )
curvature = fabsf (eigen_value / eig_sum);
else
curvature = ;
}
6.法向量定向
见normal_3d.h文件中,有多个覆写方法。摘其一:
/** \brief Flip (in place) the estimated normal of a point towards a given viewpoint
* \param point a given point
* \param vp_x the X coordinate of the viewpoint
* \param vp_y the X coordinate of the viewpoint
* \param vp_z the X coordinate of the viewpoint
* \param nx the resultant X component of the plane normal
* \param ny the resultant Y component of the plane normal
* \param nz the resultant Z component of the plane normal
* \ingroup features
*/
template <typename PointT> inline void
flipNormalTowardsViewpoint (const PointT &point, float vp_x, float vp_y, float vp_z,
float &nx, float &ny, float &nz)
{
// See if we need to flip any plane normals
vp_x -= point.x;
vp_y -= point.y;
vp_z -= point.z; // Dot product between the (viewpoint - point) and the plane normal
float cos_theta = (vp_x * nx + vp_y * ny + vp_z * nz); // Flip the plane normal
if (cos_theta < )
{
nx *= -;
ny *= -;
nz *= -;
}
}
运行的实例结果:


[PCL]2 点云法向量计算NormalEstimation的更多相关文章
- 29 基于PCL的点云平面分割拟合算法技术路线(针对有噪声的点云数据)
0 引言 最近项目中用到了基于PCL开发的基于平面的点云和CAD模型的配准算法,点云平面提取采用的算法如下. 1 基于PCL的点云平面分割拟合算法 2 参数及其意义介绍 (1)点云下采样 1. 参数: ...
- [CC]点云密度计算
包括两种计算方法:精确计算和近似计算(思考:local density=单位面积的点数 vs local density =1/单个点所占的面积) 每种方法可以实现三种模式的点云密度计算,CC里面的 ...
- 阿里云流计算专场-GitHub上相关文档
阿里云流计算专场-GitHub路径:https://github.com/Alibaba-Technology/hangzhouYunQi2017ppt
- 荣获“5G MEC优秀商用案例奖”,阿里云边缘计算发力新零售
4月24日,在中国联通合作伙伴大会的 “5G MEC(Mobile Edge Computing,移动边缘计算)边缘云赋能行业数字化转型”分论坛上,阿里云“基于5G边缘计算的新零售应用案例”荣获201 ...
- 阿里云函数计算 .NET Core 初体验
体验了一波阿里云函数计算, 已支持 .NET Core 2.1, 那么按照惯例, 来写个 "Hello World" 吧. 作者注: 开发环境 Windows 10 & V ...
- 阿里云函数计算上部署.NET Core 3.1
使用阿里云ECS或者其他常见的VPS服务部署应用的时候,需要手动配置环境,并且监测ECS的行为,做补丁之类的,搞得有点复杂.好在很多云厂商(阿里云.Azure等)提供了Serverless服务,借助于 ...
- 阿里云函数计算 VSCode 使用,及部署 Docusaurus
代码: https://github.com/ikuokuo/start-serverless 使用简介 产品页开通服务.使用流程,如下: 新手示例,如下: 创建函数 阿里云提供了如下几种方式创建函数 ...
- 对端边缘云网络计算模式:透明计算、移动边缘计算、雾计算和Cloudlet
对端边缘云网络计算模式:透明计算.移动边缘计算.雾计算和Cloudlet 概要 将数据发送到云端进行分析是过去几十年的一个突出趋势,推动了云计算成为主流计算范式.然而,物联网时代设备数量和数据流量的急 ...
- 独家对话阿里云函数计算负责人不瞋:你所不知道的 Serverless
作者 | 杨丽 出品 | 雷锋网产业组 "Serverless 其实离我们并没有那么遥远". 如果你是一名互联网研发人员,那么极有可能了解并应用过 Serverless 这套技术体 ...
随机推荐
- Foreach 与 Foreach-Object 的区别
下面两个实例可以看出: Get-ADGroupMember -Identity "CN=gAPCHN-HGZ-IE10-Users,OU=Groups,OU=Hangzhou - Chi ...
- OpenCV学习笔记——视频的边缘检测
使用Canny算子进行边缘检测,并分开输出到三个窗口中,再给每一个窗口添加文字 代码: #include"cv.h" #include"highgui.h" / ...
- HDU 1754 I Hate It(线段树单点更新区间最值查询)
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- DS实验题 Floyd最短路径 & Prim最小生成树
题目: 提示: Floyd最短路径算法实现(未测试): // // main.cpp // Alg_Floyd_playgame // // Created by wasdns on 16/11/19 ...
- 【翻译】Kinect v2程序设计(C++-) AudioBeam篇
Kinect v2,Microphone Array可以用来对于水平面音源方向的推测(AudioBeam)和语音识别(Speech Recognition).这一节是介绍如何取得AudioBeam. ...
- HTML标签之间不是可以随便嵌套的
深究:我们先来认识in-line内联元素和block-line块元素,因为HTML里几乎所有元素都属于内联元素或者块元素中的一种. in-line这个词有很多种解释:内嵌.内联.行内.线级等,但是,它 ...
- Networking with PHP
PHP Advanced and Object-Oriented Programming 3rd Edition
- 迷宫bfs POJ3984
#include<stdio.h> int map[5][5]={0,1,0,0,0, 0,1,0,1,0, 0,0,0,0,0, 0,1,1,1,0, ...
- Spring IoC反转控制的快速入门
* 下载Spring最新开发包 * 复制Spring开发jar包到工程 * 理解IoC反转控制和DI依赖注入 * 编写Spring核心配置文件 * 在程序中读取Spring配置文件,通过Spring框 ...
- fatal error C1854: 无法覆盖在创建对象文件.obj”的预编译头过程中形成的信息
原因: 将stdafx.cpp 的预编译头属性 由 创建预编译头(/Yc) 改成了 使用预编译头(/Yu) 解决: 改回为 创建预编译头(/Yc) 参考文档 http://blog.csdn.net ...