48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
import unittest
|
|
|
|
import numpy as np
|
|
import tensorflow as tf
|
|
|
|
import warp
|
|
|
|
|
|
class MyTestCase(unittest.TestCase):
|
|
def test_euler_to_rotation_matrix(self):
|
|
# quarter rotation in every
|
|
x = y = z = tf.expand_dims(tf.expand_dims(tf.constant(np.pi / 2), 0), 0)
|
|
x2 = y2 = z2 = tf.expand_dims(tf.expand_dims(tf.constant(np.pi / 4), 0), 0)
|
|
|
|
x_batch = tf.concat([x, x2], 0)
|
|
y_batch = tf.concat([y, y2], 0)
|
|
z_batch = tf.concat([z, z2], 0)
|
|
|
|
# TODO: Construct expected final rotation matrix, just 3x3 using numpy, so that we can do an
|
|
# elementwise comparison later. Probably also want to check the
|
|
|
|
rotation_matrices = warp.euler_to_matrix(x_batch, y_batch, z_batch)
|
|
# old_rot = utils.euler2mat_noNDim(x_batch, y_batch, z_batch)
|
|
|
|
self.assertEqual(rotation_matrices.shape, [2, 3, 3])
|
|
|
|
def test_coordinates(self):
|
|
height = 1000
|
|
width = 2000
|
|
coords = warp.image_coordinate(8, height, width)
|
|
|
|
self.assertEqual(coords.shape, [8, height, width, 3])
|
|
self.assertEqual(coords[0, 0, 0, 0], 0)
|
|
self.assertEqual(coords[0, 0, 0, 1], 0)
|
|
self.assertEqual(coords[0, 0, 0, 2], 1)
|
|
|
|
self.assertEqual(coords[0, height - 1, 0, 0], 0)
|
|
self.assertEqual(coords[0, height - 1, 0, 1], height - 1)
|
|
self.assertEqual(coords[0, height - 1, 0, 2], 1)
|
|
|
|
self.assertEqual(coords[0, height - 1, width - 1, 0], width - 1)
|
|
self.assertEqual(coords[0, height - 1, width - 1, 1], height - 1)
|
|
self.assertEqual(coords[0, height - 1, width - 1, 2], 1)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|