takeshi-yabuki / tips

0 stars 0 forks source link

顔判別 #3

Open takeshi-yabuki opened 5 years ago

takeshi-yabuki commented 5 years ago
# -*- coding: utf-8 -*-
from pprint import pprint

import face_recognition
import matplotlib.pyplot as plt
import numpy as np

# 画像を読み込む。
img = plt.imread('yabuki2_2_rgb.png')

# 顔の特徴点 facial landmarks を検出する。
landmarks = face_recognition.face_landmarks(img)
pprint(landmarks)

# 日本語訳
jp_names = {'nose_bridge': '鼻筋',
            'nose_tip': '鼻先',
            'top_lip': '上唇',
            'bottom_lip': '下唇',
            'left_eye': '左目',
            'right_eye': '左目',
            'left_eyebrow': '左眉毛',
            'right_eyebrow': '右眉毛',
            'chin': '下顎'}

# 可視化する。
fig, ax = plt.subplots(figsize=(7, 7))
ax.imshow(img)
ax.set_axis_off()
for face in landmarks:
    for name, points in face.items():
        points = np.array(points)
        ax.plot(points[:, 0], points[:, 1], 'o-', ms=3, label=jp_names[name])
ax.legend(fontsize=14)

plt.show()
~   
takeshi-yabuki commented 5 years ago

https://qiita.com/kekeho/items/0b2d4ed5192a4c90a0ac