64 lines
2.2 KiB
Python
64 lines
2.2 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)
|
|
|
|
def test_warp(self):
|
|
height = 1000
|
|
width = 2000
|
|
coords = warp.image_coordinate(1, height, width)
|
|
coords = tf.reshape(coords, [1, height * width, 3])
|
|
coords = tf.transpose(coords, [0, 2, 1])
|
|
# source image to sample from
|
|
img = tf.random.uniform([1, height, width, 3]) * 255
|
|
|
|
intrinsics = tf.constant([[[1, 0, 0], [0, 1, 0], [0, 0, 1]]], dtype=tf.float32)
|
|
|
|
disp = tf.random.uniform([1, height, width]) * 255
|
|
pose = tf.random.uniform([1, 6])
|
|
|
|
self.assertEqual(warp.projective_inverse_warp(img, disp, pose, intrinsics, coords).shape, img.shape)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|