Skip to content

Instantly share code, notes, and snippets.

@Puzer
Created December 25, 2019 13:00
Show Gist options
  • Save Puzer/8f954b16feded5922c4b0d37f768ece3 to your computer and use it in GitHub Desktop.
Save Puzer/8f954b16feded5922c4b0d37f768ece3 to your computer and use it in GitHub Desktop.
import tensorflow as tf
from tensorflow.contrib.image import matrices_to_flat_transforms, transform
sess = tf.Session()
# affine_M = [[ 0.14, 0. , -18.4 ],
# [ -0. , 0.14, -16.28],
# [0, 0, 1]]
affine_M = np.vstack([tfm_mean, # <- M which might be used in cv2.warpAffine
np.array([[0, 0, 1]])])
projective_M = sess.run(matrices_to_flat_transforms(tf.linalg.inv(affine_M)))
wraped_image = sess.run(transform(np.array(img),
projective_M,
output_shape=(crop_size, crop_size)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment