主要内容

本页采用了机器翻译。点击此处可查看英文原文。

pcnormals

估计点云的法线

说明

normals = pcnormals(ptCloud) 返回一个矩阵,该矩阵存储了输入 ptCloud 中每个点的法向量。该函数利用六个相邻点拟合一个局部平面,从而确定每个法向量。

示例

normals = pcnormals(ptCloud,k) 还指定了 k,即用于局部平面拟合的点数。该函数使用此值,而不是如第一种语法所述的六个邻近点。

示例

全部折叠

加载点云。

load('object3d.mat');

求出法向量。

normals = pcnormals(ptCloud);

figure
pcshow(ptCloud)
title('Estimated Normals of Point Cloud')
hold on

Figure contains an axes object. The axes object with title Estimated Normals of Point Cloud contains an object of type scatter.

x = ptCloud.Location(1:10:end,1:10:end,1);
y = ptCloud.Location(1:10:end,1:10:end,2);
z = ptCloud.Location(1:10:end,1:10:end,3);
u = normals(1:10:end,1:10:end,1);
v = normals(1:10:end,1:10:end,2);
w = normals(1:10:end,1:10:end,3);

绘制法向量。

quiver3(x,y,z,u,v,w);
hold off

Figure contains an axes object. The axes object with title Estimated Normals of Point Cloud contains 2 objects of type scatter, quiver.

将法线翻转,使其指向传感器位置。此步骤仅用于确定曲面的内向或外向方向。传感器的中心位于 xyz 坐标处。

sensorCenter = [0,-0.3,0.3]; 
for k = 1 : numel(x)
   p1 = sensorCenter - [x(k),y(k),z(k)];
   p2 = [u(k),v(k),w(k)];
   % Flip the normal vector if it is not pointing towards the sensor.
   angle = atan2(norm(cross(p1,p2)),p1*p2');
   if angle > pi/2 || angle < -pi/2
       u(k) = -u(k);
       v(k) = -v(k);
       w(k) = -w(k);
   end
end

绘制调整后的法线。

figure
pcshow(ptCloud)
title('Adjusted Normals of Point Cloud')
hold on
quiver3(x, y, z, u, v, w);
hold off

Figure contains an axes object. The axes object with title Adjusted Normals of Point Cloud contains 2 objects of type scatter, quiver.

输入参数

全部折叠

用于存储点云的对象,以 pointCloud 对象的形式返回。

用于局部平面拟合的点数,指定为大于或等于 3 的整数。增加该值可以提高精度,但会延长计算时间。如果未指定 k,该函数将使用六个相邻点拟合一个局部平面,以确定每个法向量。

输出参量

全部折叠

用于拟合局部平面的法向量,以 M×3 或 M×N×3 矩阵的形式返回。法向量是根据由 k 的值定义的邻居数量,在局部范围内计算得出的。如果 k 不是输入,则使用六个相邻点。每个法向量的方向可以根据您获取这些点的方式来设定。点云法线估计 示例演示了当法线向量指向传感器时,如何设置方向。

参考

[1] Hoppe, H., T. DeRose, T. Duchamp, J. Mcdonald, and W. Stuetzle. "Surface Reconstruction from Unorganized Points". Computer Graphics (SIGGRAPH 1992 Proceedings). 1992, pp. 71–78.

扩展功能

全部展开

C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。

版本历史记录

在 R2015b 中推出