基于Python的开源人脸识别库 离线识别率高达99 38

                                   
               

项目地址:https://github.com/ageitgey/face_recognition#face-recognition

本文的模型使用了C++工具箱dlib基于深度学习的最新人脸识别方法,基于户外脸部数据测试库Labeled Faces in the Wild 的基准水平来说,达到了99.38%的准确率。

dlibhttp://dlib.net/

数据测试库Labeled Faces in the Wild:http://vis-www.cs.umass.edu/lfw/

模型提供了一个简单的 face_recognition 命令行工具让用户通过命令就能直接使用图片文件夹进行人脸识别操作。

特征

在图片中捕捉人脸

在一张图片中捕捉到所有的人脸

找到并处理图片中人脸的特征

找到每个人眼睛、鼻子、嘴巴和下巴的位置和轮廓。

import face_recognition

image = face_recognition.load_image_file("your_file.jpg")

face_locations = face_recognition.face_locations(image)

捕捉脸部特征有很重要的用途,当然也可以用来进行图片的数字美颜digital make-up(例如美图秀秀)

digital make-up:https://github.com/ageitgey/face_recognition/blob/master/examples/digital_makeup.py

识别图片中的人脸

识别谁出现在照片里

PS:如果你想要系统地学习人工智能,那么推荐你去看床长人工智能教程。非常棒的大神之作,教程不仅通俗易懂,而且很风趣幽默。点击这里可以查看教程。

安装步骤

本方法支持Python3/python2,我们只在macOSLinux中测试过,还不知是否适用于Windows

使用pypipip3 安装此模块(或是Python 2pip2

重要提示:在编译dlib时可能会出问题,你可以通过安装来自源(而不是pip)的dlib来修复错误,请见安装手册How to install dlib from source

https://gist.github.com/ageitgey/629d75c1baac34dfa5ca2a1928a7aeaf

通过手动安装dlib,运行pip3 install face_recognition来完成安装。

使用方法命令行界面

当你安装face_recognition,你能得到一个简洁的叫做face_recognition的命令行程序,它能帮你识别一张照片或是一个照片文件夹中的所有人脸。

首先,你需要提供一个包含一张照片的文件夹,并且你已经知道照片中的人是谁,每个人都要有一张照片文件,且文件名需要以该人的姓名命名;

然后你需要准备另外一个文件夹,里面装有你想要识别人脸照片;

接下来你只用运行face_recognition命令,程序能够通过已知人脸的文件夹识别出未知人脸照片中的人是谁;

针对每个人脸都要一行输出,数据是文件名加上识别到的人名,以逗号分隔。

如果你只是想要知道每个照片中的人名而不要文件名,可以进行如下操作:

Python模块

你可以通过引入face_recognition就能完成人脸识别操作:

API 文档https://face-recognition.readthedocs.io.

在图片中自动识别所有人脸

请参照此案例this example: https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_picture.py

识别图片中的人脸并告知姓名

请参照此案例this example: https://github.com/ageitgey/face_recognition/blob/master/examples/recognize_faces_in_pictures.py

Python代码案例

所有例子在此 here.

https://github.com/ageitgey/face_recognition/tree/master/examples

·找到照片中的人脸Find faces in a photograph

https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_picture.py

· 识别照片中的面部特征Identify specific facial features in a photograph

https://github.com/ageitgey/face_recognition/blob/master/examples/find_facial_features_in_picture.py

· 使用数字美颜Apply (horribly ugly) digital make-up

https://github.com/ageitgey/face_recognition/blob/master/examples/digital_makeup.py

·基于已知人名找到并识别出照片中的未知人脸Find and recognize unknown faces in a photograph based on photographs of known people

https://github.com/ageitgey/face_recognition/blob/master/examples/recognize_faces_in_pictures.py

人脸识别方法的原理

如果你想学习此方法的人脸定位和识别原理,请参见read my article。

https://medium.com/@ageitgey/machine-learning-is-fun-part-4-modern-face-recognition-with-deep-learning-c3cffc121d78

注意事项

· 本人脸识别模型仅限用于成人,对于儿童来说效果不佳,模型可能会由于使用默认的对比阈值(0.6)而无法清楚识别出儿童的脸。

                     

更多精彩内容