本项目face_recognition是一个强大、简单、易上手的人脸识别开源项目,并且配备了完整的开发文档和应用案例,特别是兼容树莓派系统。
为了便于中国开发者研究学习人脸识别、贡献代码,我将本项目README文件翻译成中文。
向本项目的所有贡献者致敬。
英译汉:同济大学开源软件协会 子豪兄Tommy
Translator's note:
face_recognition is a powerful, simple and easy-to-use face recognition open source project with complete development documents and application cases, especially it is compatible with Raspberry Pi.
In order to facilitate Chinese software developers to learn, make progress in face recognition development and source code contributions, I translated README file into simplified Chinese.
Salute to all contributors to this project.
Translator: Tommy in Tongji Univerisity Opensource Association 子豪兄Tommy
本项目是世界上最简洁的人脸识别库,你可以使用Python和命令行工具提取、识别、操作人脸。
本项目的人脸识别是基于业内领先的C++开源库 dlib中的深度学习模型,用Labeled Faces in the Wild人脸数据集进行测试,有高达99.38%的准确率。但对小孩和亚洲人脸的识别准确率尚待提升。
Labeled Faces in the Wild是美国麻省大学安姆斯特分校(University of Massachusetts Amherst)制作的人脸数据集,该数据集包含了从网络收集的13,000多张面部图像。
本项目提供了简易的face_recognition
命令行工具,你可以用它处理整个文件夹里的图片。
特性
从图片里找到人脸
定位图片中的所有人脸:
import face_recognition image = face_recognition.load_image_file("your_file.jpg") face_locations = face_recognition.face_locations(image)
识别人脸关键点
识别人脸关键点,包括眼睛、鼻子、嘴和下巴。
import face_recognition image = face_recognition.load_image_file("your_file.jpg") face_landmarks_list = face_recognition.face_landmarks(image)
识别人脸关键点在很多领域都有用处,但同样你也可以把这个功能玩坏,比如本项目的 digital make-up自动化妆案例(就像美图秀秀一样)。
识别图片中的人是谁
import face_recognition known_image = face_recognition.load_image_file("biden.jpg") unknown_image = face_recognition.load_image_file("unknown.jpg") biden_encoding = face_recognition.face_encodings(known_image)[0] unknown_encoding = face_recognition.face_encodings(unknown_image)[0] results = face_recognition.compare_faces([biden_encoding], unknown_encoding)
你也可以配合其它的Python库(比如opencv)实现实时人脸检测:
看这个案例 实时人脸检测 。
安装
环境配置
- Python 3.3+ or Python 2.7
- macOS or Linux
- Windows并不是我们官方支持的,但也许也能用
不同操作系统的安装方法
在 Mac 或者 Linux上安装本项目
First, make sure you have dlib already installed with Python bindings:
第一步,安装dlib和相关Python依赖:
Then, install this module from pypi using pip3
(or pip2
for Python 2):
pip3 install face_recognition