利用特征估计两点云之间的变换
这个例子展示了如何估计两个点云之间的刚性变换。在本例中,您使用特征提取和匹配来显著减少估计所需的点数。在使用extractFPFHFeatures
函数从点云中提取快速点特征直方图(FPFH)特征,您可以使用pcmatchfeatures
函数在提取的特征中搜索匹配项。最后,使用estgeotform3d
函数和匹配特征来估计刚性变换。
预处理
通过对输入点云应用刚性变换来创建两个点云。
将点云数据读入工作区。
rng (“默认”ptCld = pcread(“highwayScene.pcd”);ptCld。数
Ans = 65536
对点云进行下采样以提高计算速度,因为它包含大约65,000个点。
ptCloud = pcdownsample(ptCld,gridAverage=0.2);ptCloud。数
Ans = 24596
创建一个30度旋转和平移5个单位的刚性变换矩阵x- - -y -轴。
rotAngle = 30;Trans = [5 5 0];tform = rigidtform3d([0 0 rotAngle],trans);
变换输入点云。
ptcloudtform = pctransform(ptCloud,tform);
想象两个点云。
pcshowpair (ptCloud ptCloudTformed)轴在Xlim ([-50 75]) ylim([-40 80])“原始”,“转换”,TextColor=[1 1 0])
特征提取与配准
方法从两个点云中提取特征extractFPFHFeatures
函数。
fixedFeature = extractFPFHFeatures(ptCloud);movingFeature = extractFPFHFeatures(ptCloudTformed);
查找匹配特征并显示匹配对的数量。
[matchingPairs,scores] = pcmatchfeatures(fixedFeature,movingFeature,…ptCloud ptCloudTformed方法=“详尽”);长度(matchingPairs)
Ans = 1814
从点云中选择匹配点。
fixedPts = select(ptCloud,matchingPairs(:,1));matchingPts = select(ptCloudTformed,matchingPairs(:,2));
利用匹配点估计变换矩阵。
estimatedTform = estgeotform3d(fixedPts. 3d)的位置,…matchingPts。的位置,“刚性”);disp (estimatedTform.A)
0.8660 -0.5000 -0.0003 4.9995 0.5000 0.8660 0.0000 5.0022 0.0002 -0.0002 1.0000 0.0020 000 1.0000
显示定义的变换矩阵。
disp (tform.A)
0.8660 -0.5000 0 5.0000 0.5000 0.8660 0 5.0000 00 1.0000 0000 1.0000
使用估计的转换进行重新转换ptCloudTformed
回到最初的点云。
ptCloudTformed = pctransform(ptCloudTformed,invert(estimatedTform));
想象两个点云。
pcshowpair (ptCloud ptCloudTformed)轴在Xlim ([-50 50]) ylim([-40 60]) title(“对齐点云”)