机器学习与数据挖掘深度学习数字图像处理与计算机视觉(python)

2020机器学习人脸识别(1)

2020-02-16  本文已影响0人  zidea
machine_learning.jpg

MTCNN

MTCNN 分为三个网络,PNET,RNET,ONET,

mtcnn_001.jpeg
import cv2
import matplotlib.pyplot as plt
import tensorflow as tf

from mtcnn import MTCNN
img = cv2.imread('face_dataset/ironman_actor.jpg')
img_grb = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
plt.imshow(img_grb)
plt.axis("off")
(-0.5, 927.5, 522.5, -0.5)
output_3_1.png
detector = MTCNN()
result = detector.detect_faces(img_grb)
result
[{'box': [411, 70, 219, 306],
  'confidence': 0.9999737739562988,
  'keypoints': {'left_eye': (491, 194),
   'right_eye': (585, 196),
   'nose': (548, 245),
   'mouth_left': (499, 307),
   'mouth_right': (575, 307)}}]
bounding_box = result[0]['box']
right_eye = result[0]['keypoints']['right_eye']
left_eye = result[0]['keypoints']['left_eye']
nose = result[0]['keypoints']['nose']
mouth_left = result[0]['keypoints']['mouth_left']
mouth_right = result[0]['keypoints']['mouth_right']
# cv2.circle(img_grb,(bounding_box[1],bounding_box[0]),20,(255, 0, 0),-1 )
# cv2.circle(img_grb,(bounding_box[3],bounding_box[2]),20,(255, 0, 0),-1 )

cv2.circle(img_grb,(right_eye[0],right_eye[1]),5,(0, 255, 0),-1 )
cv2.circle(img_grb,(left_eye[0],left_eye[1]),5,(0, 255, 0),-1 )
cv2.circle(img_grb,(nose[0],nose[1]),5,(0, 255, 0),-1 )
cv2.circle(img_grb,(mouth_left[0],mouth_left[1]),5,(0, 255, 0),-1 )
cv2.circle(img_grb,(mouth_right[0],mouth_right[1]),5,(0, 255, 0),-1 )

plt.imshow(img_grb)
<matplotlib.image.AxesImage at 0x1449c1c88>
output_7_1.png

最后希望大家关注我们微信公众号


wechat.jpeg
上一篇 下一篇

猜你喜欢

热点阅读