Mtcnn进行人脸剪裁和对齐

 from scipy import misc
import tensorflow as tf
import detect_face
import cv2
# import matplotlib.pyplot as plt
from PIL import Image
import os
# import scipy.misc
# %pylab inline
fin = 'D:\data\male'
fout = 'D:\data\\rain\male'
minsize = 20 # minimum size of face
threshold = [0.6, 0.7, 0.7] # three steps's threshold
factor = 0.709 # scale factor
margin = 44
frame_interval = 3
batch_size = 1000
image_size = 182
input_image_size = 160 print('Creating networks and loading parameters') with tf.Graph().as_default():
gpu_options = tf.GPUOptions(allow_growth=True)
sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options, log_device_placement=False))
with sess.as_default():
pnet, rnet, onet = detect_face.create_mtcnn(sess, 'D:\\code\\real-time-deep-face-recognition-master\\20170512-110547') i= 0 for file in os.listdir(fin):
try: file_fullname = fin + '/' + file
img = misc.imread(file_fullname)
# i+= 1
# img = misc.imread(image_path)
bounding_boxes, _ = detect_face.detect_face(img, minsize, pnet, rnet, onet, threshold, factor)
nrof_faces = bounding_boxes.shape[0] # 人脸数目
print(nrof_faces)
#print('找到人脸数目为:{}'.format(nrof_faces)) # print(bounding_boxes) crop_faces = []
if nrof_faces != 0 :
for face_position in bounding_boxes:
face_position = face_position.astype(int)
print(face_position[0:4])
cv2.rectangle(img, (face_position[0], face_position[1]), (face_position[2], face_position[3]), (0, 255, 0), 2)
crop = img[face_position[1]:face_position[3],
face_position[0]:face_position[2], ]
# print(crop)
# crop = cv2.resize(crop, (96, 96), interpolation=cv2.INTER_CUBIC)
crop_faces.append(crop)
img2 = Image.open(file_fullname)
a = face_position[0:4]
# print('crop_faces:',crop_faces)
# a = [face_position[0:4]]
box = (a)
roi = img2.crop(box)
i = roi.resize((224, 224)) out_path = fout + '/' + file i.save(out_path)
print('success')
else:
pass
except:
pass

Mtcnn进行人脸剪裁和对齐B的更多相关文章

  1. Mtcnn进行人脸剪裁和对齐

    from scipy import misc import tensorflow as tf import detect_face import cv2 import matplotlib.pyplo ...

  2. 第三十七节、人脸检测MTCNN和人脸识别Facenet(附源码)

    在说到人脸检测我们首先会想到利用Harr特征提取和Adaboost分类器进行人脸检测(有兴趣的可以去一看这篇博客第九节.人脸检测之Haar分类器),其检测效果也是不错的,但是目前人脸检测的应用场景逐渐 ...

  3. MTCNN 实现人脸识别

    MTCNN(Multi-task CNN) MTCNN难点 WIDER FACE等数据集为我们提供的图片并不是MTCNN支持的训练样本, 需要通过几个脚本将其转为MTCNN可以接受的数据集, 这些脚本 ...

  4. facenet 人脸识别(二)——创建人脸库搭建人脸识别系统

    搭建人脸库 选择的方式是从百度下载明星照片 照片下载,downloadImageByBaidu.py # coding=utf-8 """ 爬取百度图片的高清原图 &qu ...

  5. 算法---FaceNet理论学习篇

    FaceNet算法-理论学习篇 @WP20190228 ==============目 录============ 一.LFW数据集简介 二.FaceNet算法简介 FaceNet算法=MTCNN模型 ...

  6. FaceNet pre-trained模型以及FaceNet源码使用方法和讲解

    Pre-trained models Model name LFW accuracy Training dataset Architecture 20180408-102900 0.9905 CASI ...

  7. 使用TensorRT对人脸检测网络MTCNN进行加速

    前言 最近在做人脸比对的工作,需要用到人脸关键点检测的算法,比较成熟和通用的一种算法是 MTCNN,可以同时进行人脸框选和关键点检测,对于每张脸输出 5 个关键点,可以用来进行人脸对齐. 问题 刚开始 ...

  8. 机器学习--详解人脸对齐算法SDM-LBF

    引自:http://blog.csdn.net/taily_duan/article/details/54584040 人脸对齐之SDM(Supervised Descent Method) 人脸对齐 ...

  9. 机器学习----人脸对齐的算法-ASM.AAM..CLM.SDM

    引自:http://blog.csdn.net/linolzhang/article/details/55271815 人脸检测 早已比较成熟,传统的基于HOG+线性分类器 的方案检测效果已经相当不错 ...

随机推荐

  1. web3.js

      安装 别按照官网上面 npm install web3 下载,我已经吃过一次亏了 npm initnpm install ethereum/web3.js --save   web3.isConn ...

  2. SQL Server 远程更新目标表数据

    分享一个远程更新目标库数据的存储过程,适用于更新列名一致,主键为Int类型,可远程链接的数据库. ** 温馨提示:如需转载本文,请注明内容出处.** 本文连接:http://www.cnblogs.c ...

  3. Partitions - Partition Storage Modes and Processing-MOLAP、ROLAP、HOLAP

    https://docs.microsoft.com/en-us/sql/analysis-services/multidimensional-models-olap-logical-cube-obj ...

  4. STOMP协议规范

    原文: STOMP Protocol Specification, Version 1.2 摘要 STOMP是一个简单的可互操作的协议, 被用于通过中间服务器在客户端之间进行异步消息传递.它定义了一种 ...

  5. java类定义、变量类型、构造函数

    1.java类class的定义 所有java程序都以类class为组织单元,java类由属性和方法组成,下面看例子: public  class  Phone{ //属性 String company ...

  6. jsp 条件查询、列表分页

    条件查询 dao //根据搜索条件筛选数据 public List<User> GetUserBySearch(String userName, String sex) throws SQ ...

  7. Python_struct模块操作二进制文件

    ''' 使用struct模块写入二进制文件 ''' import struct n=130000000 x=96.45 b=True s='a1@中国' sn=struct.pack('if?',n, ...

  8. mybatis查询异常-Error querying database. Cause: java.lang.ClassCastException: org.apache.ibatis.executor.ExecutionPlaceholder cannot be cast to java.util.List

    背景,mybatis查询的时候直接取的sqlsession,没有包装成SqlSessionTemplate,没有走spring提供的代理. 然后我写的获取sqlsession的代码没有考虑到并发的情况 ...

  9. MySQL中查询时"Lost connection to MySQL server during query"报错的解决方案

    一.问题描述: mysql数据库查询时,遇到下面的报错信息: 二.原因分析: dw_user 表数据量比较大,直接查询速度慢,容易"卡死",导致数据库自动连接超时.... 三.解决 ...

  10. 【转】深入理解margin

    由浅入深漫谈margin属性 2007-3-18 上午 - HTML/CSS/XML/XSL - CSS - margin margin 在中文中我们翻译成外边距或者外补白(本文中引用外边距).他是元 ...