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 

相关推荐

  1. 基于SVD的

    2024-02-06 21:32:01       8 阅读
  2. 类相关文献阅读记录

    2024-02-06 21:32:01       11 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-02-06 21:32:01       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-02-06 21:32:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-02-06 21:32:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-02-06 21:32:01       18 阅读

热门阅读

  1. 数据结构-队列

    2024-02-06 21:32:01       29 阅读
  2. 记一次面试题

    2024-02-06 21:32:01       25 阅读
  3. 观察者模式

    2024-02-06 21:32:01       33 阅读
  4. 【技术预研】StarRocks官方文档浅析(4)

    2024-02-06 21:32:01       40 阅读
  5. go常见问题

    2024-02-06 21:32:01       29 阅读
  6. 1001 A+B Format - PAT(Advance Level)Practive

    2024-02-06 21:32:01       30 阅读
  7. 原语,原子,线程安全

    2024-02-06 21:32:01       34 阅读
  8. 深度学习本科课程 实验3 网络优化

    2024-02-06 21:32:01       30 阅读
  9. docker进阶问题一

    2024-02-06 21:32:01       36 阅读