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

作者: zidea | 来源:发表于2020-02-16 21:07 被阅读0次
    machine_learning.jpg

    MTCNN

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

    mtcnn_001.jpeg
    • 首先会生成图形金字塔,这个在学习 SIFT 特征提取时候,提及到图像金字塔,为了模拟我们在不同大小和模糊程度对图像中特征提取而将图像按尺寸和模糊程度生成一系列大小不同的图。
    • 然后将这些图片输入PNET,PNET 会粗略提取人脸的候选框和回归量
    • 接下来经过 RNET ,RNET 进一步筛选去掉效果不好人脸框,选出比较准确的人脸框
    • 最后就是 ONET 经过计算会输出一个人脸框和 5 个点,两个点位于人脸的眼睛和两个点位于嘴角一个点位于鼻子


      mtcnn_002.png
    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

    相关文章

      网友评论

        本文标题:2020机器学习人脸识别(1)

        本文链接:https://www.haomeiwen.com/subject/mkgmfhtx.html