def homography2theta(homography, height, width):
if not isinstance(homography, np.ndarray):
homography = homography.detach().cpu().numpy()
batch_size = homography.shape[0]
homography = np.linalg.inv(homography)
theta = np.zeros((batch_size, 2, 3), dtype=np.float32)
theta[:, 0, 0] = homography[:, 0, 0]
theta[:, 0, 1] = homography[:, 0, 1] * height / width
theta[:, 0, 2] = homography[:, 0, 2] * 2 / width + theta[:, 0, 0] + theta[:, 0, 1] - 1
theta[:, 1, 0] = homography[:, 1, 0] * width / height
theta[:, 1, 1] = homography[:, 1, 1]
theta[:, 1, 2] = homography[:, 1, 2] * 2 / height + theta[:, 1, 0] + theta[:, 1, 1] - 1
return theta
Conversion between affine matrix and ‘theta‘
于 2020-11-28 15:50:57 首次发布