根据两个坐标系对应点计算转换关系(旋转和平移)

在两组对应的三维点数据之间寻找最佳的旋转和平移,使它们对齐/注册,是我遇到的一个常见问题。下面给出了3个对应点的最简单情况(需要解决的最小点)。
在这里插入图片描述
对应点的颜色相同,R是旋转,t是平移。我们想要找到将数据集A中的点与数据集b对齐的最佳旋转和平移。这种变换有时被称为欧几里德变换或刚性变换,因为它保持了形状和大小。这与仿射变换形成对比,仿射变换包括缩放和剪切。

我将给出的解决方案来自于Besl和McKay在1992年发表的论文:
“A Method for Registration of 3-D Shapes’, by Besl and McKay, 1992.”

解决方案概述

我们正在求解方程中的R,t:
B = R*A + t
其中R,t是应用于数据集A的变换,使其与数据集B尽可能对齐。求最优刚性变换矩阵可分解为以下步骤:
1.求两个数据集的质心
2.将两个数据集带到原点,然后求最优旋转(矩阵R)
3.求平移t

求质心

求质心这一点很简单,质心只是平均点,可以计算如下:
在这里插入图片描述

求最优旋转

有几种方法可以找到点之间的最佳旋转。我发现最简单的方法是使用奇异值分解(SVD),

为了找到最佳的旋转,我们首先将两个数据集重新居中,使两个中心点都位于原点,如下图所示。
在这里插入图片描述在这里插入图片描述
H是协方差矩阵。

特殊情况
if determinant(R) < 0
  multiply 3rd column of V by -1
  recompute R
end if

An alternative check that is possibly more robust was suggested by Nick Lambert, where R is the rotation matrix.

if determinant(R) < 0
  multiply 3rd column of R by -1
end if

在这里插入图片描述

Matlab代码
% This function finds the optimal Rigid/Euclidean transform in 3D space
% It expects as input a Nx3 matrix of 3D points.
% It returns R, t

% You can verify the correctness of the function by copying and pasting these commands:
%{

R = orth(rand(3,3)); % random rotation matrix

if det(R) < 0
    V(:,3) *= -1;
    R = V*U';
end

t = rand(3,1); % random translation

n = 10; % number of points
A = rand(n,3);
B = R*A' + repmat(t, 1, n);
B = B';

[ret_R, ret_t] = rigid_transform_3D(A, B);

A2 = (ret_R*A') + repmat(ret_t, 1, n)
A2 = A2'

% Find the error
err = A2 - B;
err = err .* err;
err = sum(err(:));
rmse = sqrt(err/n);

disp(sprintf("RMSE: %f", rmse));
disp("If RMSE is near zero, the function is correct!");

%}

% expects row data
function [R,t] = rigid_transform_3D(A, B)
    if nargin != 2
	    error("Missing parameters");
    end

    assert(size(A) == size(B))

    centroid_A = mean(A);
    centroid_B = mean(B);

    N = size(A,1);

    H = (A - repmat(centroid_A, N, 1))' * (B - repmat(centroid_B, N, 1));

    [U,S,V] = svd(H);

    R = V*U';

    if det(R) < 0
        printf("Reflection detected\n");
        V(:,3) = -1*V(:,3);
        R = V*U';
    end

    t = -R*centroid_A' + centroid_B'
end

在这里插入图片描述

 centroid_A = mean(A);
 centroid_B = mean(B);

  N = size(A,1);

  H = (A - repmat(centroid_A, N, 1))' * (B - repmat(centroid_B, N, 1));

  A_move=A - repmat(centroid_A, N, 1);
  B_move=B - repmat(centroid_B, N, 1);

  A_norm=sum(A_move.*A_move,2);
  B_norm=sum(B_move.*B_move,2);

  %计算尺度平均值
  lam2=A_norm./B_norm;
  lam2=mean(lam2);

  [U,S,V] = svd(H);
  R = V*U';

  if det(R) < 0
  printf('Reflection detected\n');
  V(:,3) = -1*V(:,3);
  R = V*U';
  end
  %计算最终的旋转矩阵与平移向量
  t = -R./(lam2^(0.5))*centroid_A' + centroid_B';
  R = R./(lam2^(0.5));
  end

参考自:
http://nghiaho.com/?page_id=671
https://blog.csdn.net/sinat_29886521/article/details/77506426?utm_source=blogxgwz0

  • 23
    点赞
  • 161
    收藏
    觉得还不错? 一键收藏
  • 29
    评论
三点解算是一种常用的坐标系转换方法,它适用于平面上两个坐标系转换。三点解算的基本思想是通过已知的三个点在两个坐标系中的坐标,推导出两个坐标系转换关系,从而实现坐标系转换。以下是具体的计算步骤: 1. 确定三个已知点的坐标和对应的坐标系。这三个点应该位于两个坐标系的交界处,其中一个点的坐标可以是原点(0,0),另外两个点的坐标应该具有一定距离差,避免误差积累。 2. 假设两个坐标系转换关系是仿射变换,即可以表示为旋转平移和缩放的组合。用一个4*4的矩阵表示变换关系,如下所示: | a11 a12 a13 tx | | a21 a22 a23 ty | | 0 0 1 0 | | 0 0 0 1 | 其中,a11、a12、a21、a22是旋转和缩放的参数,tx、ty是平移的参数。 3. 用已知点的坐标完成对矩阵中参数的解。具体步骤如下: • 用已知点在坐标系1中的坐标表示仿射变换关系,得到四个未知参数。 • 用已知点在坐标系2中的坐标表示仿射变换关系,得到四个未知参数。 • 将以上两个方程写成矩阵形式,即Ax=B,其中A是一个6*4的矩阵,由已知坐标组成;x是一个4*1的矩阵,包括未知参数;B是一个6*1的矩阵,同样由已知坐标组成。 • 解出矩阵x,就可以得到两个坐标系转换关系。 经过以上步骤,就可以通过三点解算得到两个坐标系转换关系。在实际应用中,可以使用该关系完成不同坐标系下的点的坐标转换,以满足不同领域的定位、导航、地图等应用需

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 29
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值