主要内容

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

pctransform

对三维点云进行变换

说明

ptCloudOut = pctransform(ptCloudIn,tform) 对点云 ptCloudIn 应用指定的 三维 仿射变换 tform。该变换可以是刚变换、相似变换或仿射变换。

示例

ptCloudOut = pctransform(ptCloudIn,D) 将位移场 D 应用到点云上。使用位移场对点云进行变换,即针对点云中的每个点定义平移量。

示例

示例

全部折叠

读取点云数据。

ptCloud = pcread('teapot.ply');

绘制点云图。

figure
pcshow(ptCloud)
xlabel('X')
ylabel('Y')
zlabel('Z')

Figure contains an axes object. The axes object with xlabel X, ylabel Y contains an object of type scatter.

创建一个沿 z 轴旋转 45 度的变换对象。

rotationAngles = [0 0 45];
translation = [0 0 0];
tform = rigidtform3d(rotationAngles,translation);

对点云进行变换。

ptCloudOut = pctransform(ptCloud,tform);

绘制变换后的点云图。

figure
pcshow(ptCloudOut)
xlabel('X')
ylabel('Y')
zlabel('Z')

Figure contains an axes object. The axes object with xlabel X, ylabel Y contains an object of type scatter.

本示例对一个三维点云应用了刚性变换(旋转)和非刚性变换(剪切)。

将点云读入工作区。

ptCloud = pcread('teapot.ply');

绘制原始的三维点云。

figure1 = figure;
axes1 = axes(Parent=figure1);
pcshow(ptCloud,Parent=axes1,AxesVisibility='on'); 
xlabel('X');
ylabel('Y');
zlabel('Z');
title('3-D Point Cloud',FontSize=14)

Figure contains an axes object. The axes object with title 3-D Point Cloud, xlabel X, ylabel Y contains an object of type scatter.

三维点云的旋转

创建一个刚体变换对象,该对象定义了沿 z 轴的 45 度旋转。

rotationAngles = [0 0 45];
translation = [0 0 0];
tform = rigidtform3d(rotationAngles,translation);

对点云进行变换。

ptCloudOut1 = pctransform(ptCloud,tform);

绘制旋转后的点云图。

figure2 = figure;
axes2 = axes(Parent=figure2);
pcshow(ptCloudOut1,Parent=axes2,AxesVisibility='on');
xlabel('X');
ylabel('Y');
zlabel('Z');
title({'Rotation of 3-D Point Cloud'},FontSize=14)

Figure contains an axes object. The axes object with title Rotation of 3-D Point Cloud, xlabel X, ylabel Y contains an object of type scatter.

三维点云的剪切

创建一个仿射变换对象,该对象定义了沿 x 轴的剪切变换。

A = [1 0.75 0.75 0; ...
     0   1    0  0; ...
     0   0    1  0; ...
     0   0    0  1];
tform = affinetform3d(A);

对点云进行变换。

ptCloudOut2 = pctransform(ptCloud,tform);

绘制变换后的点云图。

figure3 = figure;
axes3 = axes(Parent=figure3);
pcshow(ptCloudOut2,Parent=axes3,AxesVisibility='on');
xlabel('X');
ylabel('Y');
zlabel('Z');
title({'Shearing of 3-D Point Cloud'},FontSize=14)

Figure contains an axes object. The axes object with title Shearing of 3-D Point Cloud, xlabel X, ylabel Y contains an object of type scatter.

将点云读入工作区。

ptCloud = pcread('teapot.ply');

创建一个与点云尺寸相同的位移字段 D

D = zeros(size(ptCloud.Location));

将前半部分数据点沿 x 轴的位移字段值设置为 7。

pthalf = ptCloud.Count/2;
D(1:pthalf,1) = 7;

使用 pointCloud 方法 findNeighborsInRadius 提取感兴趣区域 (ROI) 内各点的索引。将 ROI 内各点沿 xyz 轴的位移字段值分别设置为 4、4 和-2。

indices = findNeighborsInRadius(ptCloud,[0 0 3.1],1.5);
D(indices,1:2) = 4;
D(indices,3) = -2;

使用位移字段对点云进行变换。

ptCloudOut = pctransform(ptCloud,D);

显示原始点云和变换后的点云。

figure
pcshow(ptCloud)
xlabel('X');
ylabel('Y');
zlabel('Z');
title('Original 3-D Point Cloud')

Figure contains an axes object. The axes object with title Original 3-D Point Cloud, xlabel X, ylabel Y contains an object of type scatter.

figure
pcshow(ptCloudOut)
xlabel('X');
ylabel('Y');
zlabel('Z');
title('Transformed 3-D Point Cloud Using Displacement Field')

Figure contains an axes object. The axes object with title Transformed 3-D Point Cloud Using Displacement Field, xlabel X, ylabel Y contains an object of type scatter.

输入参数

全部折叠

点云,指定为 pointCloud 对象。

三维几何变换,指定为 rigidtform3dsimtform3daffinetform3d 目标。有关如何设置仿射三维 tform 输入的详细信息,请参阅Specify Transformation Matrix

位移字段,指定为 M×3 或一个 M×N×3 数组。位移场是一组位移向量,用于指定点云中每个点的平移幅值和方向。位移场的尺寸必须与 pointCloud 对象的 Location 属性的尺寸相同。

数据类型: single | double

输出参量

全部折叠

经过变换的点云,以 pointCloud 对象的形式返回。该变换适用于点的坐标及其法向量。

扩展功能

全部展开

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

版本历史记录

在 R2015a 中推出

全部展开