• 03-人脸识别-基于MTCNN,显示5个人脸特征


    import tensorflow as tf
    import numpy as np
    import cv2
    import detect_face
    import matplotlib.pyplot as plt
    import math
    from scipy import misc
    
    img = misc.imread('face_airplane.jpg')
    
    sess = tf.Session()
    pnet, rnet, onet = detect_face.create_mtcnn(sess, None)
    
    # pnet, rnet, onet are 3 funtions
    
    minsize = 20
    threshold = [0.6, 0.7, 0.7]
    factor = 0.709
    df_result, df_points_result = detect_face.detect_face(img, minsize, pnet, rnet, onet, threshold, factor)
    
    n_face = df_result.shape[0]
    print('detected face number: {}'.format(n_face))
    print(df_result)
    
    plt.figure('faces')
    i = 0
    plt_nrow = n_face / 5
    plt_nrow = plt_nrow + int(n_face != plt_nrow * 5)
    
    plt_ncol = 5
    crop_face = []
    for subfaceRec in df_result:
        i = i + 1
        subfaceRec = subfaceRec.astype(int)
        img_a_face = img[subfaceRec[1]:subfaceRec[3], subfaceRec[0]:subfaceRec[2]]
        crop_face.append(img_a_face)
        img_a_face = cv2.resize(img_a_face, (96, 96), interpolation=cv2.INTER_CUBIC)
    
        print('plt_nrow:{}, plt_ncol:{}, i:{}'.format(plt_nrow, plt_ncol, i))
        plt.subplot(plt_nrow, plt_ncol, i)
        plt.imshow(img_a_face)
    
        cv2.rectangle(img, (subfaceRec[0], subfaceRec[1]), (subfaceRec[2], subfaceRec[3]), (0, 255, 0), 2)
    
    # draw points
    # df_points_result is faceNumber X 10
    # need transpose to 10 X faceNumber
    df_points_result = np.transpose(df_points_result)
    
    for subPoints in df_points_result:
        # subPoints: [x1,x2,x3,x4,x5,y1,y2,y3,y4,y5]
        cv2.circle(img, (subPoints[0], subPoints[5]), 2, (255, 0, 0), -1) # Red left eye
        cv2.circle(img, (subPoints[1], subPoints[6]), 2, (0, 0, 255), -1) # Blue right eye
        cv2.circle(img, (subPoints[2], subPoints[7]), 2, (0, 255, 0), -1) # Green nose
        cv2.circle(img, (subPoints[3], subPoints[8]), 2, (255, 255, 0), -1) # yellow left mouse
        cv2.circle(img, (subPoints[4], subPoints[9]), 2, (0, 255, 255), -1) # cyan right mouse
    
    plt.figure('img')
    plt.imshow(img)
    plt.show()
    
    sess.close()
    

      

    还有待优化。

  • 相关阅读:
    jmeter_04_常用取样器
    jmeter_03_鉴权
    jmeter_02_目录文档说明
    jmeter_01_常用快捷键
    Web Api 与 Andriod 接口对接开发经验
    Eclipse自动生成作者、日期注释等功能设置
    c#解析XML到DATASET及dataset转为xml文件函数
    Jquery 仿 android Toast效果
    正在运行的android程序,按home键之后退回到桌面,在次点击程序图标避免再次重新启动程序解决办法
    异步网络加载开源框架AsyncHttpClient使用
  • 原文地址:https://www.cnblogs.com/alexYuin/p/8849990.html
Copyright © 2020-2023  润新知