基于MTCNN卷积神经网络的人脸识别
该文作者开源了测试代码,源代码可以在我之前的文章中或者Github中去下载,我对源代码的数据输入部分做了一些改动以更方便的实现人脸检测,即将 facedetect_mtcnn.py主函数文件更改为如下代码:
# coding=utf-8
from __future__ import absolute_import
from __future__ import division
from __future__ import print_functionimport sys
import os
import argparse
import tensorflow as tf
import numpy as np
import detect_face
import cv2
import time
import shutildef reseach_image_name(root_dir):if (os.path.exists(root_dir)):fileNames = os.listdir(root_dir)fileNames = sorted(fileNames)return fileNamesdef main(input_file_list):sess = tf.Session()pnet, rnet, onet = detect_face.create_mtcnn(sess, None)minsize = 40 # minimum size of facethreshold = [0.6, 0.7, 0.9] # three steps's thresholdfactor = 0.709 # scale factoroutput_root_dir = "./output_face_result"if (not os.path.exists(output_root_dir)):os.mkdir(output_root_dir )# 假如path_01 = 'Test\\path_01\\path_02\\path_03',os.mkdir(path_01)创建路径中的最后一级目录,# 即:只创建path_03目录,而如果之前的目录不存在并且也需要创建的话,就会报错。# os.makedirs(path_01)创建多层目录,即:Test,path_01,path_02,path_03如果都不存在的话,会自动创建。else:shutil.rmtree(output_root_dir ) # 先删除原来的目录os.mkdir(output_root_dir) # 再创建一个新目录for index in range(len(input_file_list)):print("***********开始检测第%d张图像***********"%index)filename = input_file_list[index]input_image_dir = os.path.join( input_root_dir, filename)output_image_dir =os.path.join( output_root_dir,filename.split(".")[0]+"_result.jpg")draw = cv2.imread(input_image_dir)# cv2.imshow("source image",draw )# cv2.waitKey(0)# cv2.destroyAllWindows()img = cv2.cvtColor(draw, cv2.COLOR_BGR2RGB)bounding_boxes, points = detect_face.detect_face(img, minsize, pnet, rnet, onet, threshold, factor)nrof_faces = bounding_boxes.shape[0]for b in bounding_boxes:cv2.rectangle(draw, (int(b[0]), int(b[1])), (int(b[2]), int(b[3])), (0, 255, 0))print("人脸坐标:{0}".format(b))for p in points.T:for i in range(5):cv2.circle(draw, (p[i], p[i + 5]), 1, (0, 0, 255), 2)print('总共%d个人脸被检测到,保存到%s' % (nrof_faces, output_image_dir))cv2.imshow("detected image", draw)cv2.waitKey(0)cv2.destroyAllWindows()cv2.imwrite(output_image_dir, draw)def detect_video_face(video_file):sess = tf.Session()pnet, rnet, onet = detect_face.create_mtcnn(sess, None)minsize = 40 # minimum size of facethreshold = [0.6, 0.7, 0.9] # three steps's thresholdfactor = 0.709 # scale factorcamera = cv2.VideoCapture(video_file)while True:(grabbed, frame) = camera.read()if grabbed == True:img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)# cv2.imshow("frame",frame)bounding_boxes, points = detect_face.detect_face(img, minsize, pnet, rnet, onet, threshold, factor)nrof_faces = bounding_boxes.shape[0]for b in bounding_boxes:cv2.rectangle(frame, (int(b[0]), int(b[1])), (int(b[2]), int(b[3])), (0, 255, 0))print("人脸坐标:{0}".format(b))for p in points.T:for i in range(5):cv2.circle(frame, (p[i], p[i + 5]), 1, (0, 0, 255), 2)print('总共%d个人脸被检测到' %nrof_faces)cv2.imshow("detected image", frame)if cv2.waitKey(1) & 0xFF == ord('q'):# 通过cap.read() 的返回值ret,若ret值为False,则停止捕获视频。breakcap.release()cv2.destroyAllWindows()def detect_single_pic(image_file):sess = tf.Session()pnet, rnet, onet = detect_face.create_mtcnn(sess, None)minsize = 40 # minimum size of facethreshold = [0.6, 0.7, 0.9] # three steps's thresholdfactor = 0.709 # scale factorprint("***********开始检测图像***********" )filename = image_filedraw = cv2.imread(filename)cv2.imshow("source image", draw)cv2.waitKey(0)cv2.destroyAllWindows()img = cv2.cvtColor(draw, cv2.COLOR_BGR2RGB)bounding_boxes, points = detect_face.detect_face(img, minsize, pnet, rnet, onet, threshold, factor)nrof_faces = bounding_boxes.shape[0]for b in bounding_boxes:cv2.rectangle(draw, (int(b[0]), int(b[1])), (int(b[2]), int(b[3])), (0, 255, 0))print("人脸坐标:{0}".format(b))for p in points.T:for i in range(5):cv2.circle(draw, (p[i], p[i + 5]), 1, (0, 0, 255), 2)print('总共%d个人脸被检测到'% nrof_faces)cv2.imshow("detected image", draw)cv2.waitKey(0)cv2.destroyAllWindows()if __name__ == '__main__':input_root_dir = "./input_face_image"input_file_list = reseach_image_name( input_root_dir)main(input_file_list)
新建了两个文件夹,一个文件夹放待检测的图片,另一个文件夹放检测后的结果图片,如下所示:
这是 input_face_image文件夹下的待测试图片:
运行程序,可以看到检测效果:
......
当然,检测结果图片都被保存到了 output_face_image文件夹下。
基于MTCNN卷积神经网络的人脸识别相关推荐
- 基于深度卷积神经网络进行人脸识别的原理是什么?
原文:https://www.zhihu.com/question/60759296 基于深度卷积神经网络进行人脸识别的原理是什么? 这里的人脸识别包括但不限于:人脸检测,人脸对齐,身份验证识别,和表 ...
- 基于CNN卷积神经网络的人脸识别
一.利用卷积神经网络进行人脸检测,称作CFF(卷积人脸搜索) 卷积神经网络人脸识别的大致流程: 1)对本地人脸进行特征提取 2)打开摄像头(opencv) 3)从cap获取信息 4)找人脸 5)对人脸 ...
- 基于深度卷积神经网络的人脸识别考勤系统-VGG-PYTHON-QT(1)
本项目设计并实现了一个应用于小型企业员工考勤的刷脸考勤系统,整个系统使用Python语言开发,并利用Pyqt5作为桌面端系统界面的开发工具,以SQL Server作为数据库管理系统,最终集成所有刷脸考 ...
- 基于卷积神经网络的人脸识别(自我拍摄获取数据集)
基于卷积神经网络的人脸识别 完整代码.数据请见:https://download.csdn.net/download/weixin_43521269/12837110 人脸识别,是基于人的脸部特征信息 ...
- python人脸识别系统界面设计_基于卷积神经网络的人脸识别系统的设计(Python)
基于卷积神经网络的人脸识别系统的设计(Python)(论文10000字,外文翻译,参考代码,流程图,人脸图像库) 摘要:随着社会的进步与发展,个人信息的保护变得十分重要.传统的密码保护方式已经不再满足 ...
- 博士论文——基于卷积神经网络的人脸识别研究 __张燕红
论文题目 作者 年份 关键词 链接 备注 基于卷积神经网络的人脸识别研究 张燕红 2018 人脸识别:卷积神经网络:特征提取:分块策略:正则化 博士论文 摘要:随着信息技术的蓬勃发展,人们的学习和生活 ...
- 基于卷积神经网络的人脸识别算法
摘要:近年来,随着科学技术的不断发展,人脸识别技术日渐成熟,使得人脸识别技术的使用率不断增大.例如:门禁.ATM机.公安系统以及新兴起的人机交互等领域,都应用到了人脸识别系统.在人脸识别研究领域中,深 ...
- 深度学习(十五)基于级联卷积神经网络的人脸特征点定位
基于级联卷积神经网络的人脸特征点定位 原文地址:http://blog.csdn.net/hjimce/article/details/49955149 作者:hjimce 一.相关理论 本篇博文主要 ...
- 【转】干货|孙启超:卷积神经网络在人脸识别技术中的应用
2018-08-27 21:45:01 随着 iPhone X 的发布,Face ID 人脸识别技术开始进入人们的日常生活中,当我们拿起手机并看着它的时候就可以实现手机解锁的功能.而人脸识别中的关键技 ...
最新文章
- Python 将字符串转为字典
- 过滤Java集合的最佳方法是什么?
- zookeeper安装( windows环境)
- svn: Can't find a temporary directory 问题解决
- 程序员编程艺术第一~十章集锦与总结(教你如何编程)--持续更新中
- anaconda安装python视频_怎么安装anaconda?
- 各种排序算法比较--2015年7月23日22:33:43v1.0版
- 禁止ASP.NET MVC模型绑定时将空字符串绑定为null
- 反客为主 ,Linux 成为微软 Azure 上最流行的操作系统
- vue当前页引入js_「vue基础」新手入门导航(一)
- But don‘t be fooled, this phone does not
- 【ROS学习笔记】(十二)常用可视化工具
- asp fso的神奇功能
- Activity的启动模式standard,singleTop,singleTask,singleInstance(转)
- 如何开启刷题,蓝桥杯练习系统
- 【常识】常用RGB颜色对照表
- 7-9 旅游规划 (25 分)Dijkstra算法,单源最短路径算法
- 平稳分布、细致平稳条件与 Gibbs 采样
- 四VCO单声道/多声道合成器:KORG Polysix for mac
- Image类--旋转和翻转图片
热门文章
- OSPF 特殊区域介绍、Stub、Totally Stub、NSSA、Totally NSSA
- 行人reid ,多个开源地址数据变成 market1501格式合并,附代码,数据地址
- 解决操作无法完成,因为其中的文件夹或文件已在另一程序中打开的问题
- ps切片工具里没有html,PS切片工具怎么用?PS切片工具的使用方法
- 数据库的备份与恢复(一)
- 百脑汇 Ghost_XP_SP3 电子城国庆版 2012.10
- 计算机算法常用术语中英对照
- 百度地图BMap API的应用实例
- 关于线程同步的几种方法
- Android开发:按一定频率同时获取多个传感器数据