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

相关推荐
醇醛酸醚酮酯15 分钟前
Qt项目锻炼——TODO清单(二)
开发语言·数据库·qt
jioulongzi21 分钟前
记录一次莫名奇妙的跨域502(badgateway)错误
开发语言·python
向阳@向远方1 小时前
第二章 简单程序设计
开发语言·c++·算法
Mr_Xuhhh1 小时前
信号与槽的总结
java·开发语言·数据库·c++·qt·系统架构
纳兰青华2 小时前
bean注入的过程中,Property of ‘java.util.ArrayList‘ type cannot be injected by ‘List‘
java·开发语言·spring·list
好开心啊没烦恼2 小时前
Python 数据分析:DataFrame,生成,用字典创建 DataFrame ,键值对数量不一样怎么办?
开发语言·python·数据挖掘·数据分析
liulilittle2 小时前
VGW 虚拟网关用户手册 (PPP PRIVATE NETWORK 基础设施)
开发语言·网络·c++·网关·智能路由器·路由器·通信
Devil枫2 小时前
Kotlin高级特性深度解析
android·开发语言·kotlin
ChinaDragonDreamer2 小时前
Kotlin:2.1.20 的新特性
android·开发语言·kotlin
安之若素^2 小时前
启用不安全的HTTP方法
java·开发语言