Created
March 5, 2020 16:39
-
-
Save miracleyoo/4a9e18e2d84a47bd09d4aa467d494cd8 to your computer and use it in GitHub Desktop.
[Plot Facial Landmark] #python #plot #face #landmark
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 collections | |
pred_type = collections.namedtuple('prediction_type', ['slice', 'color']) | |
pred_types = {'face': pred_type(slice(0, 17), (0.682, 0.780, 0.909, 0.5)), | |
'eyebrow1': pred_type(slice(17, 22), (1.0, 0.498, 0.055, 0.4)), | |
'eyebrow2': pred_type(slice(22, 27), (1.0, 0.498, 0.055, 0.4)), | |
'nose': pred_type(slice(27, 31), (0.345, 0.239, 0.443, 0.4)), | |
'nostril': pred_type(slice(31, 36), (0.345, 0.239, 0.443, 0.4)), | |
'eye1': pred_type(slice(36, 42), (0.596, 0.875, 0.541, 0.3)), | |
'eye2': pred_type(slice(42, 48), (0.596, 0.875, 0.541, 0.3)), | |
'lips': pred_type(slice(48, 60), (0.596, 0.875, 0.541, 0.3)), | |
'teeth': pred_type(slice(60, 68), (0.596, 0.875, 0.541, 0.4)) | |
} | |
def landmark_plot_2d(img, lmark): | |
"""2D Landmark Plot | |
Args: | |
img: The input image. A numpy array. | |
""" | |
plot_style = dict(marker='o', | |
markersize=3, | |
linestyle='-', | |
lw=2) | |
fig = plt.figure(figsize=plt.figaspect(.5)) | |
ax = fig.add_subplot(1,1,1) | |
ax.imshow(img) | |
for pred_type in pred_types.values(): | |
ax.plot(lmark[pred_type.slice, 0], | |
lmark[pred_type.slice, 1], | |
color=pred_type.color, **plot_style) | |
ax.axis('off') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment