Last active
October 23, 2022 08:31
-
-
Save yuhanz/10d9177c9348804bd439f1f5a579c555 to your computer and use it in GitHub Desktop.
Python - Given 2 transformation matrices of the same object in different scene, deduce the camera movement.
This file contains hidden or 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
import numpy as np | |
transform1 = [ -0.24934738874435425,-0.04462388902902603,-0.9673854112625122,0, | |
-0.0016946435207501054,0.9989563822746277,-0.045643400400877,0, | |
0.9684126377105713,-0.009741689078509808,-0.24916277825832367,0, | |
0.6389213800430298,1.247190237045288,26.812557220458984,1] | |
transform2 = [ -0.9929033517837524,-0.05427047982811928,0.1058192104101181,0, | |
-0.05242447182536125,-0.5989430546760559,-0.7990738153457642,0, | |
0.10674579441547394,-0.7989505529403687,0.5918474197387695,0, | |
3.77003812789917,3.94081449508667,92.34391784667969,1] | |
m1 = np.matrix(np.array(transform1).reshape((4,4))) | |
m2 = np.matrix(np.array(transform2).reshape((4,4))) | |
inv = np.linalg.inv(m1) | |
object_movement = inv * m2 | |
## camera movement should be the reverse of the object movement | |
# translation = object_movement.copy() | |
# rotation = object_movement.copy() | |
# translation[0][0:4] = [1.0, 0.0, 0.0, 0.0] | |
# translation[1][0:4] = [0.0, 1.0, 0.0, 0.0] | |
# translation[2][0:4] = [0.0, 0.0, 1.0, 0.0] | |
# rotation[3][0:4] = [0.0, 0.0, 0.0, 1.0] | |
# camera_movement = np.linalg.inv(translation) * np.linalg.inv(rotation) | |
camera_movement = np.linalg.inv(object_movement) | |
print("camera_movement:", camera_movement) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment