Created
June 5, 2020 10:02
-
-
Save velikodniy/ac43b727b3e7c625fa14bfecb2ccc1fc to your computer and use it in GitHub Desktop.
dlib-like aligning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import skimage | |
import numpy as np | |
LANDMARKS_SRC = np.array([[0.30392274, 0.29713595], | |
[0.68197238, 0.29713595], | |
[0.53872643, 0.57810357], | |
[0.38641786, 0.67528929], | |
[0.60154214, 0.76057500]]) | |
def align(image, landmarks, size=(200, 200)): | |
assert landmarks.shape == (5, 2) | |
align_transform = skimage.transform.SimilarityTransform() | |
align_transform.estimate(LANDMARKS_SRC * size, landmarks) | |
image_aligned = skimage.transform.warp(image, align_transform, | |
output_shape=size, preserve_range=True) | |
return image_aligned |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment