• 01-人脸识别-基于MTCNN,框选人脸区域-detect_face_main


    (本系列随笔持续更新)

    搭建要求

    详细的搭建过程在 参考资料1 中已经有啦。

    TensorFlow 1.6.0

    OpenCV 2.4.8 仅仅是加载和读取图片的需要

    Ubuntu 14.04 64bits

    代码:加载图片,找出人脸。运行依赖detect_face.py

    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)
    
    minsize = 20
    threshold = [0.6, 0.7, 0.7]
    factor = 0.709
    df_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)
    
    
    fig = 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
      
      #ax = fig.subplot(plt_nrow, plt_ncol, i)
      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)
      #plt.imshow(img_a_face)
      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)
      
    plt.figure('img')
    plt.imshow(img)
    plt.show()
    
    sess.close()
    

      

    显示效果:

     

    参考资料:

    1 https://blog.csdn.net/mr_evanchen/article/details/77650883

    2 https://github.com/ShyBigBoy/face-detection-mtcnn

  • 相关阅读:
    尾递归
    gcc/g++ 命令
    GCC输出带C源代码的汇编文件
    linux下Ctrl命令组合
    静态链接库(lib)、动态链接库(dll)与动态链接库的导入库(lib)
    VS2010-MFC(菜单:菜单及CMenu类的使用)
    VS2010-MFC(菜单:VS2010菜单资源详解)
    VS2010-MFC(常用控件:标签控件Tab Control 下)
    VS2010-MFC(常用控件:标签控件Tab Control 上)
    VS2010-MFC(常用控件:树形控件Tree Control 下)
  • 原文地址:https://www.cnblogs.com/alexYuin/p/8820534.html
Copyright © 2020-2023  润新知