Created
August 3, 2020 03:50
-
-
Save qzane/a19be2b54e2ac20d2d72a9d15f90dfb0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solve_RT1_RT2(A, B): | |
''' solve for B = x1.dot(A).dot(x2) | |
A = [[[R1,T1],[0,1]]...] # shape: (n,4,4) | |
B = [[[R2,T2],[0,1]]...] # shape: (n,4,4) | |
minimize{np.einsum('jk,ikp,pq->ijq', x1, A, x2)-B} | |
return: x1,x2: shape(4,4) | |
''' | |
def func(x,a,b): | |
x1 = x[:16].reshape(4,4) | |
x2 = x[16:].reshape(4,4) | |
tmp = np.einsum('jk,ikp,pq->ijq', x1, a, x2) | |
return (tmp - b).reshape(-1) | |
#init = np.ones((32,), np.float) | |
init = np.concatenate((np.identity(4,np.float).reshape(-1), np.identity(4, np.float).reshape(-1))) | |
xx,_ = scipy.optimize.leastsq(func, init, args=(A,B)) | |
return xx[:16].reshape(4,4),xx[16:].reshape(4,4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment