def test_randomly_rotate_and_project_sequences_3d_to_2d(self): keypoints_3d_t1 = tf.constant([[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], [[7.0, 8.0, 9.0], [10.0, 11.0, 12.0]], [[13.0, 14.0, 15.0], [16.0, 17.0, 18.0]]]) keypoints_3d_t2 = tf.constant([[[1.2, 2.2, 3.2], [4.2, 5.2, 6.2]], [[7.4, 8.4, 9.4], [10.4, 11.4, 12.4]], [[13.8, 14.8, 15.8], [16.8, 17.8, 18.8]]]) keypoints_3d_t3 = tf.constant([[[1.5, 2.5, 3.5], [4.5, 5.5, 6.5]], [[7.6, 8.6, 9.6], [10.6, 11.6, 12.6]], [[13.7, 14.7, 15.7], [16.7, 17.7, 18.7]]]) keypoints_3d = tf.stack( [keypoints_3d_t1, keypoints_3d_t2, keypoints_3d_t3], axis=-3) keypoints_2d = keypoint_utils.randomly_rotate_and_project_3d_to_2d( keypoints_3d, azimuth_range=(math.pi / 2.0, math.pi / 2.0), elevation_range=(-math.pi / 2.0, -math.pi / 2.0), roll_range=(math.pi, math.pi), default_camera_z=2.0, sequential_inputs=True) self.assertAllClose( keypoints_2d, [[[[-1.0 / 5.0, 2.0 / 5.0], [-4.0 / 8.0, 5.0 / 8.0]], [[-1.2 / 5.2, 2.2 / 5.2], [-4.2 / 8.2, 5.2 / 8.2]], [[-1.5 / 5.5, 2.5 / 5.5], [-4.5 / 8.5, 5.5 / 8.5]]], [[[-7.0 / 11.0, 8.0 / 11.0], [-10.0 / 14.0, 11.0 / 14.0]], [[-7.4 / 11.4, 8.4 / 11.4], [-10.4 / 14.4, 11.4 / 14.4]], [[-7.6 / 11.6, 8.6 / 11.6], [-10.6 / 14.6, 11.6 / 14.6]]], [[[-13.0 / 17.0, 14.0 / 17.0], [-16.0 / 20.0, 17.0 / 20.0]], [[-13.8 / 17.8, 14.8 / 17.8], [-16.8 / 20.8, 17.8 / 20.8]], [[-13.7 / 17.7, 14.7 / 17.7], [-16.7 / 20.7, 17.7 / 20.7]]]])
def test_randomly_rotate_and_project_3d_to_2d(self): keypoints_3d = tf.constant([[[2.0, 1.0, 3.0], [5.0, 4.0, 6.0]], [[8.0, 7.0, 9.0], [11.0, 10.0, 12.0]], [[14.0, 13.0, 15.0], [17.0, 16.0, 18.0]]]) keypoints_2d = keypoint_utils.randomly_rotate_and_project_3d_to_2d( keypoints_3d, azimuth_range=(math.pi / 2.0, math.pi / 2.0), elevation_range=(-math.pi / 2.0, -math.pi / 2.0), roll_range=(math.pi, math.pi), normalized_camera_depth_range=(2.0, 2.0)) self.assertAllClose( keypoints_2d, [[[-1.0 / 4.0, -3.0 / 4.0], [-4.0 / 7.0, -6.0 / 7.0]], [[-7.0 / 10.0, -9.0 / 10.0], [-10.0 / 13.0, -12.0 / 13.0]], [[-13.0 / 16.0, -15.0 / 16.0], [-16.0 / 19.0, -18.0 / 19.0]]])
def test_randomly_rotate_and_project_3d_to_2d(self): keypoints_3d = tf.constant([[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], [[7.0, 8.0, 9.0], [10.0, 11.0, 12.0]], [[13.0, 14.0, 15.0], [16.0, 17.0, 18.0]]]) keypoints_2d = keypoint_utils.randomly_rotate_and_project_3d_to_2d( keypoints_3d, azimuth_range=(math.pi / 2.0, math.pi / 2.0), elevation_range=(-math.pi / 2.0, -math.pi / 2.0), roll_range=(math.pi, math.pi), default_camera_z=2.0) self.assertAllClose( keypoints_2d, [[[-1.0 / 5.0, 2.0 / 5.0], [-4.0 / 8.0, 5.0 / 8.0]], [[-7.0 / 11.0, 8.0 / 11.0], [-10.0 / 14.0, 11.0 / 14.0]], [[-13.0 / 17.0, 14.0 / 17.0], [-16.0 / 20.0, 17.0 / 20.0]]])
def test_randomly_rotate_and_project_sequences_3d_to_2d(self): # Shape = [1, 4, 2, 3]. keypoints_3d = tf.constant([[[[2.0, 1.0, 3.0], [5.0, 4.0, 6.0]], [[2.1, 1.1, 3.1], [5.1, 4.1, 6.1]], [[2.2, 1.2, 3.2], [5.2, 4.2, 6.2]], [[2.3, 1.3, 3.3], [5.3, 4.3, 6.3]]]]) # Shape = [1, 4, 2, 2]. keypoints_2d = keypoint_utils.randomly_rotate_and_project_3d_to_2d( keypoints_3d, azimuth_range=(math.pi / 2.0, math.pi / 2.0), elevation_range=(-math.pi / 2.0, -math.pi / 2.0), roll_range=(math.pi, math.pi), normalized_camera_depth_range=(2.0, 2.0), sequential_inputs=True) self.assertAllClose( keypoints_2d, [[[[-1.0 / 4.0, -3.0 / 4.0], [-4.0 / 7.0, -6.0 / 7.0]], [[-1.1 / 4.1, -3.1 / 4.1], [-4.1 / 7.1, -6.1 / 7.1]], [[-1.2 / 4.2, -3.2 / 4.2], [-4.2 / 7.2, -6.2 / 7.2]], [[-1.3 / 4.3, -3.3 / 4.3], [-4.3 / 7.3, -6.3 / 7.3]]]])