Matlab使用点云工具箱进行点云配准

一、代码

Matlab 复制代码
source_pc = pcread('bun_zipper.ply');
target_pc = pcread('bun_zipper2.ply');
% 下采样
gridStep = 0.001;
ptCloudA = pcdownsample(source_pc,'gridAverage',gridStep);
ptCloudB = pcdownsample(target_pc,'gridAverage',gridStep);
% 初始变换矩阵
tform_initial = affine3d();

% 执行点云配准
tform = pcregistericp(ptCloudA,ptCloudB,'Extrapolate',true);

% 提取平移向量
translation = tform.T(4, 1:3);

% 提取旋转矩阵
rotation_matrix = tform.T(1:3, 1:3);

% 将旋转矩阵转换为欧拉角
eulerAngles = rotm2eul(rotation_matrix);

% 应用配准变换到源点云
registered_source_pc = pctransform(source_pc, tform);

% 打印信息
fprintf('变换矩阵:')
disp(tform.T)
fprintf('平移量 (x, y, z): %.4f, %.4f, %.4f\n', translation(1), translation(2), translation(3));
fprintf('欧拉角 (rx, ry, rz): %.4f, %.4f, %.4f\n', rad2deg(eulerAngles(3)), rad2deg(eulerAngles(2)), rad2deg(eulerAngles(1)));

% 可视化结果
figure("Name", "原图像与配准后的图像");
set(gcf,'position',[150 80 1000 800])
subplot(2,1,1)
pcshowpair(ptCloudA, ptCloudB, 'MarkerSize', 20,'BackgroundColor',"white");
title('原图像');
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
view(2)
legend('Target Point Cloud', 'Source Point Cloud');
%figure("Name", "配准后的图像");
subplot(2,1,2)
pcshowpair(target_pc, registered_source_pc, 'MarkerSize', 20,'BackgroundColor',"white");
title('配准后的图像');
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
view(2)
legend('Target Point Cloud', 'Registered Source Point Cloud');

% 调整子图之间的距离
h = gcf; % 获取当前图形的句柄
h.Children(1).Position(2) = h.Children(1).Position(2) + 0.05; % 调整第一个子图的位置
h.Children(2).Position(2) = h.Children(2).Position(2) - 0.05; % 调整第二个子图的位置

二、结果

三、工具箱安装和示例文件

工具箱:链接:https://pan.baidu.com/s/1hMnNSQ_fIYasApViHPLsww

提取码:wstc

示例文件:链接:https://pan.baidu.com/s/1ql_q4jnUZjlZL3l3fRo8vQ

提取码:wstc

相关推荐
广州服务器托管14 小时前
[2026.1.6]WINPE运维版20260106,带网络功能的PE维护系统
运维·开发语言·windows·计算机网络·个人开发·可信计算技术
a努力。14 小时前
京东Java面试被问:双亲委派模型被破坏的场景和原理
java·开发语言·后端·python·面试·linq
冰暮流星14 小时前
javascript赋值运算符
开发语言·javascript·ecmascript
谢娘蓝桥14 小时前
adi sharc c/C++ 语言指令优化
开发语言·c++
刘975314 小时前
【第25天】25c#今日小结
java·开发语言·c#
豆沙沙包?14 小时前
2026年--Lc330-394. 字符串解码(栈)--java版
java·开发语言
2501_9418008814 小时前
从微服务限流到系统稳定性的互联网工程语法实践与多语言探索
开发语言·python
清水白石00814 小时前
《深度剖析 Pandas GroupBy:底层实现机制与性能瓶颈全景解析》
开发语言·python·numpy
2501_9418752814 小时前
从资源隔离到多租户安全的互联网工程语法构建与多语言实践分享
java·开发语言
hui函数14 小时前
python全栈入门到实战【基础篇 03】入门实操:第一个Python程序 + PyCharm使用 + 输入输出全解析
开发语言·python·pycharm