【问题标题】:How to find affine transformation matrix between two sets of 3D points?如何找到两组 3D 点之间的仿射变换矩阵?
【发布时间】:2019-05-16 10:10:08
【问题描述】:

我需要为视频的每一帧注册一些 3D 面部标志。对于这个任务,我试图找出为连续帧给出的几个地标坐标之间的转换矩阵。例如,第 1 帧和第 2 帧中 3 个地标的 3D 坐标为:

frame1 = [2 4 15; 4 15 14; 20 11 7]
frame2 = [16 5 12; 5 7 9; 11 6 19]

我尝试过使用matlab提供的imregtform函数和matlab的ABSOR工具。

tform = imregtform(frame1, frame2, 'affine','OnePlusOneEvolutionary','MeanSquares');

tform = absor(frame1, frame2)

使用imregtform时出现如下错误:

Error using imregtform>parseInputs (line 261)
The value of 'MovingImage' is invalid. All dimensions of the moving image should be greater than 4.

Error in imregtform (line 124)
parsedInputs = parseInputs(varargin{:});

注意:ABSOR 没有找到仿射变换,它找到了相似变换。

【问题讨论】:

  • imregtform 需要图像数据,而不是控制点。
  • 您可能正在寻找estimateGeometricTransform 函数。但是请注意,这需要Computer Vision Toolbox。无论如何,该函数是为 2D 数据创建的,因此您可能想了解执行此操作的算法,并尝试找到它们对 3d 数据的实现。也许OpenCV 有类似的东西。

标签: matlab affinetransform


【解决方案1】:

首先,3 个点太少,无法恢复仿射变换——你需要 4 个点。对于 N 维空间,有一个简单的规则:要明确地恢复仿射变换,您应该知道形成单纯形的 N+1 个点的图像 --- 2D 的三角形,3D 的金字塔等。使用 3 个点,您只能检索 2D仿射变换。您可以在“Beginner's guide to mapping simplexes affinely”中找到对为什么会出现这种情况的一个很好的解释。

关于一些检索算法。恐怕,我不知道 Matlab 能否为您提供合适的代码,但我使用过 Python 一点点,也许这段代码可以提供帮助(抱歉代码风格不好——我是数学家,不是程序员)

import numpy as np
# input data
ins = [[1, 1, 2], [2, 3, 0], [3, 2, -2], [-2, 2, 3]]  # <- points
out = [[0, 2, 1], [1, 2, 2], [-2, -1, 6], [4, 1, -3]] # <- mapped to
# calculations
l = len(ins)
B = np.vstack([np.transpose(ins), np.ones(l)])
D = 1.0 / np.linalg.det(B)
entry = lambda r,d: np.linalg.det(np.delete(np.vstack([r, B]), (d+1), axis=0))
M = [[(-1)**i * D * entry(R, i) for i in range(l)] for R in np.transpose(out)]
A, t = np.hsplit(np.array(M), [l-1])
t = np.transpose(t)[0]
# output
print("Affine transformation matrix:\n", A)
print("Affine transformation translation vector:\n", t)
# unittests
print("TESTING:")
for p, P in zip(np.array(ins), np.array(out)):
  image_p = np.dot(A, p) + t
  result = "[OK]" if np.allclose(image_p, P) else "[ERROR]"
  print(p, " mapped to: ", image_p, " ; expected: ", P, result)

这段代码演示了如何将仿射变换恢复为矩阵和向量,并测试初始点是否映射到它们应该映射到的位置。它基于“Beginner's guide to mapping simplexes affinely”中提出的方程,矩阵恢复在“规范符号的恢复”部分中进行了描述。同一作者发表了“Workbook on mapping simplexes affinely”,其中包含许多此类实际示例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多