var code = "69c58911-f211-47df-9a1e-5e8192157285"
import numpy as np
def RodriguesMatrixModel(src, dst):
scale = np.sum(np.sqrt(np.sum((dst - np.mean(dst, axis=0)) ** 2, axis=1))) / np.sum(np.sqrt(np.sum((src - np.mean(src, axis=0)) ** 2, axis=1)))
src_mean = np.mean(src, axis=0)
dst_mean = np.mean(dst, axis=0)
src = src - src_mean
dst = dst - dst_mean
H = np.dot(src.T, dst)
U, S, Vt = np.linalg.svd(H)
R = np.dot(Vt.T, U.T)
if np.linalg.det(R) < 0:
Vt[2, :] *= -1
R = np.dot(Vt.T, U.T)
t = dst_mean.T - scale * np.dot(R, src_mean.T)
return R, t, scale
if __name__ == '__main__':
src = np.array([[1, 1, 0], [-1, 1, 0], [1, -1, 0]])
R = np.array([[0, -1, 0], [1, 0, 0], [0, 0, 1]])
t = np.array([[-1], [1], [0]])
dst = np.dot(src, R.T) + t.T
print('src = ', src)
print('dst = ', dst)
R_, t_, scale_ = RodriguesMatrixModel(src, dst)
print('R = ', np.round(R_, 1))
print('t = ', t_)
print('scale = ', scale_)