Add coordinates generation implementation

This commit is contained in:
Piv
2021-08-08 22:11:50 +09:30
parent ece37843ce
commit 8016f0f945
2 changed files with 43 additions and 2 deletions

View File

@@ -72,7 +72,28 @@ def pose_vec2mat(vec):
return transform_mat
def projective_inverse_warp(target_img, source_img, depth, pose, intrinsics):
def image_coordinate(batch, height, width):
"""
Construct a tensor for the given height/width with elements the homogenous coordinates for the pixel
:param batch: Number of images in a batch
:param height: Height of image
:param width: Width of image
:return: Tensor of shape (B, height, width, 3), homogenous coordinates for an image.
Coordinates are in order [x, y, 1]
"""
x_coords = tf.range(width)
y_coords = tf.range(height)
x_mesh, y_mesh = tf.meshgrid(x_coords, y_coords)
ones_mesh = tf.cast(tf.ones([height, width]), tf.int32)
stacked = tf.stack([x_mesh, y_mesh, ones_mesh], axis=2)
return tf.repeat(tf.expand_dims(stacked, axis=0), batch, axis=0)
def projective_inverse_warp(target_img, source_img, depth, pose, intrinsics, coordinates):
"""
Calculate the reprojected image from the source to the target, based on the given depth, pose and intrinsics
@@ -88,12 +109,14 @@ def projective_inverse_warp(target_img, source_img, depth, pose, intrinsics):
:param depth: Tensor, (batch, height, width, 1)
:param pose: (batch, 6)
:param intrinsics: (batch, 3, 3)
:param coordinates: (batch, height, width, 3) - coordinates for the image. Pass this in so it doesn't need to be
calculated on every warp step
:return: The source image reprojected to the target
"""
# Convert pose vector (output of pose net) to pose matrix (4x4)
# Convert intrinsics matrix (3x3) to (4x4) so it can be multiplied by the pose net
intrinsics_4x4 =
# intrinsics_4x4 =
# Calculate inverse of the 4x4 intrinsics matrix
tf.linalg.inv()