Spaces:
Runtime error
Runtime error
Create transformations.py
Browse files- transformations.py +44 -0
transformations.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
def get_translation_t(t):
|
| 3 |
+
"""Get the translation matrix for movement in t."""
|
| 4 |
+
matrix = [
|
| 5 |
+
[1, 0, 0, 0],
|
| 6 |
+
[0, 1, 0, 0],
|
| 7 |
+
[0, 0, 1, t],
|
| 8 |
+
[0, 0, 0, 1],
|
| 9 |
+
]
|
| 10 |
+
return tf.convert_to_tensor(matrix, dtype=tf.float32)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def get_rotation_phi(phi):
|
| 14 |
+
"""Get the rotation matrix for movement in phi."""
|
| 15 |
+
matrix = [
|
| 16 |
+
[1, 0, 0, 0],
|
| 17 |
+
[0, tf.cos(phi), -tf.sin(phi), 0],
|
| 18 |
+
[0, tf.sin(phi), tf.cos(phi), 0],
|
| 19 |
+
[0, 0, 0, 1],
|
| 20 |
+
]
|
| 21 |
+
return tf.convert_to_tensor(matrix, dtype=tf.float32)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def get_rotation_theta(theta):
|
| 25 |
+
"""Get the rotation matrix for movement in theta."""
|
| 26 |
+
matrix = [
|
| 27 |
+
[tf.cos(theta), 0, -tf.sin(theta), 0],
|
| 28 |
+
[0, 1, 0, 0],
|
| 29 |
+
[tf.sin(theta), 0, tf.cos(theta), 0],
|
| 30 |
+
[0, 0, 0, 1],
|
| 31 |
+
]
|
| 32 |
+
return tf.convert_to_tensor(matrix, dtype=tf.float32)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def pose_spherical(theta, phi, t):
|
| 36 |
+
"""
|
| 37 |
+
Get the camera to world matrix for the corresponding theta, phi
|
| 38 |
+
and t.
|
| 39 |
+
"""
|
| 40 |
+
c2w = get_translation_t(t)
|
| 41 |
+
c2w = get_rotation_phi(phi / 180.0 * np.pi) @ c2w
|
| 42 |
+
c2w = get_rotation_theta(theta / 180.0 * np.pi) @ c2w
|
| 43 |
+
c2w = np.array([[-1, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 1]]) @ c2w
|
| 44 |
+
return c2w
|