如何确定具有坐标对的变换矩阵?

How to determine transformation matrix having coordinate pairs?

所以。我有 4 组坐标对。一个在世界坐标中,另一个在相机坐标中。

+-----+-----+-----+-----+-----+
| Xw  | Yw  | Zw  | Xc  | Yc  |
+-----+-----+-----+-----+-----+
| 0,0 | 0,0 | 0,0 | 582 | 344 |
| 7,0 | 0,0 | 0,0 | 834 | 338 |
| 0,0 | 5,0 | 0,0 | 586 | 529 |
| 7,0 | 5,0 | 0,0 | 841 | 522 |
+-----+-----+-----+-----+-----+

Xw, Yw, Zw - World coordinates
Xc, Yc - Camera coordinates
Zw - is always 0

现在我需要为此计算一个变换矩阵。所以有 Xw 和 Yw 我可以产生 Xc, Yc.

我还有摄像头 2。然后,使用摄像头 2 的一些点位置,我需要计算第一个摄像头坐标中的相同点。

+-------+-------+-------+-------+
| Xc2   | Yc2   | Xс1   | Yс1   |
+-------+-------+-------+-------+
|  1250 |   433 |   209 |   771 |
|   528 |   452 |  1277 |   730 |
+-------+-------+-------+-------+
# `Xc1` and `Yc1` just estimated for example - need to be calculated

我们还有来自 OpenCV 的相机 2 校准数据。

谢谢。

P.s。如果您能描述如何使用 python + numpy

,我将不胜感激

P.s.s.而且,如果您将其描述为橡皮鸭 (wenk) :)

您可能需要仔细考虑场景的几何形状,但是线性代数可能会给您合理的结果。

如果我们采用您的世界坐标来拟合一般形式aX + bY +c,那么我们可以使用numpy's lstsq函数进行最小二乘法拟合。

world = numpy.array([
    [0,0,0],
    [7,0,0],
    [0,5,0],
    [7,4,0]])
    
camera = numpy.array([
    [582,344],
    [834,338],
    [586,529],
    [841,522]])
    
#Lose Z axis
world = world[:,0:2]

#Make a square matrix
A = numpy.vstack([world.T, numpy.ones(4)]).T

#perform the least squares method
x, res, rank, s = numpy.linalg.lstsq(A, camera, rcond=None)

#test results
print(numpy.dot(A,x))