1. Face Recognition 库简介:

中文文档:
[face_recognition/README_Simplified_Chinese.md]

Face Recognition 库主要封装了dlib这一 C++ 图形库,通过 Python 语言将它封装为一个非常简单就可以实现人脸识别的 API 库,屏蔽了人脸识别的算法细节,大大降低了人脸识别功能的开发难度, face_recognition是基于dlib进行了二次封装,号称世界上最简洁的人脸识别库。
(1)github地址:https://github.com/ageitgey/face_recognition
(2)官方指南:face_recognition软件包 — 人脸识别 1.4.0 文档 (face-recognition.readthedocs.io)

2. Win10/Python3.6/Pycharm安装face_recognition人脸识别库步骤:

关于face_recognition包的安装,pycharm中并不包含,所以需要下载外部导入。
(1) dlib的安装步骤:
(1)首先电脑中需要安装Visual Studio
dlib在Windows系统下的编译依赖于Visual C++,所以需要安装Visual Studio,为dlib的安装提供Visual C++编译器支持。
(2)安装 cmake

pip install cmake

(3)安装dlib
访问Links for dlib (pypi.org),选择适合适的dlib版本的安装包进行下载,然后进行离线安装。
在pycharm中启动python命令行,输入:

pip install  D:\microsoft_down\dlib-19.24.0.tar.gz

(注意!!!下载下来的文件名是dlib-19.24.0.tar,实际上是一个压缩包,所以在安装时要加上压缩包后缀.gz)
安装过程比较久,待界面上出现【Successfully installed dlib-19.24.0】提示时,dlib安装成功。

(2) 安装face_recognition_models

下载 face_recognition_models 0.3.0, 然后进行离线安装。
在pycharm中启动python命令行,输入:

pip install  D:\microsoft_down\face_recognition_models-0.3.0.gz

待界面上出现【Successfully installed face_recognition_models-0.3.0】提示时,face_recognition_models安装成功。
(3)安装face_recognition
在pycharm中启动python命令行,输入:

python setup.py install

待界面上出现【Finished processing dependencies for face-recognition==1.4.0】提示时,face_recognition安装成功。

3. face_recognition库进行人脸识别的步骤:

  1. 在图片中查找人脸

import face_recognition
image = face_recognition.load_image_file("your_file.jpg")
face_locations = face_recognition.face_locations(image)
  1. 查找和操作图片中的面部特征

获取每个人的眼睛,鼻子,嘴巴和下巴的位置和轮廓。

import face_recognition
image = face_recognition.load_image_file("your_file.jpg")
face_landmarks_list = face_recognition.face_landmarks(image)
  1. 给脸部编码
    根据面部特征点计算这个面孔的特征值(特征向量)


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)
unknown_encoding = face_recognition.face_encodings(unknown_image)
  1. 识别图片中的人脸

识别每张照片中出现的用户

results = face_recognition.compare_faces([biden_encoding], unknown_encoding)

4. face_recognition人脸识别库对应的 API 接口:

(1)face_recognition.api.batch_face_locations(图像,number_of_times_to_upsample=1,batch_size=128)

使用 cnn 人脸检测器返回图像中人脸边界框的 2d 数组 如果您使用的是 GPU,这可以为您提供更快的结果,因为 GPU 可以一次处理成批的图像。如果您没有使用GPU,则不需要此功能。
参数:
images – 图像列表(每个图像作为 numpy 数组)number_of_times_to_upsample - 对图像进行上采样以查找人脸的次数。数字越高,面孔越小。batch_size – 每个 GPU 处理批处理中要包含的图像数。
返回:
按 css 顺序(上、右、下、左)找到的人脸位置的元组列表

(2)face_recognition.api.compare_faces(known_face_encodings、face_encoding_to_check、公差=0.6)

将人脸编码列表与候选编码进行比较,以查看它们是否匹配。
参数:
known_face_encodings – 已知人脸编码列表face_encoding_to_check – 用于与列表进行比较的单人脸编码容差 – 脸之间的距离,以将其视为匹配项。越低越严格。0.6 是典型的最佳性能。
返回:
真/假值列表,指示哪些known_face_encodings与要检查的人脸编码匹配

(3)face_recognition.api.face_distance(face_encodings,face_to_compare)

给定人脸编码列表,将它们与已知人脸编码进行比较,并获取每个比较人脸的欧氏距离。距离告诉您人脸的相似程度。
参数:
face_encodings – 要比较的人脸编码列表face_to_compare – 要与之进行比较的人脸编码
返回:
一个 numpy ndarray,其每张面的距离与“面”数组的顺序相同

(4)face_recognition.api.face_encodings(face_image,known_face_locations=无,num_jitters=1,模型='小')

给定一个图像,返回图像中每个人脸的 128 维人脸编码。
参数:
face_image – 包含一张或多张人脸的图像known_face_locations - 可选 - 每张脸的边界框(如果您已经知道的话)。num_jitters – 计算编码时对人脸重新采样的次数。越高越准确,但越慢(即 100 表示慢 100 倍)模型 – 可选 - 要使用的模型。“大”或“小”(默认),仅返回5分但速度更快。
返回:
128 维人脸编码的列表(图像中每个人脸一个)

(5)face_recognition.api.face_landmarks(face_image,face_locations=无,模型='大')

给定图像,返回图像中每个人脸的人脸特征位置(眼睛、鼻子等)的字典
参数:
face_image – 要搜索的图像face_locations – (可选)提供要检查的人脸位置列表。模型 – 可选 - 要使用的模型。“大”(默认)或“小”,仅返回5分但速度更快。
返回:
人脸特征位置(眼睛、鼻子等)的字典列表

(6)face_recognition.api.face_locations(img,number_of_times_to_upsample=1,model='hog')

返回图像中人脸的边界框数组
参数:
img – 图像(作为数字数组)number_of_times_to_upsample - 对图像进行上采样以查找人脸的次数。数字越高,面孔越小。model – 要使用的人脸检测模型。“hog”在CPU上不太准确,但更快。“cnn”是一个更准确的深度学习模型,它是GPU / CUDA加速的(如果可用)。默认值为“hog”。
返回:
按 css 顺序(上、右、下、左)找到的人脸位置的元组列表


(7)face_recognition.api.load_image_file(文件,模式 ='RGB')

将图像文件(.jpg、.png等)加载到numpy数组中
参数:
文件 – 要加载的图像文件名或文件对象mode ―要将图像转换为的格式。仅支持“RGB”(8 位 RGB,3 个通道)和“L”(黑白)。
返回:
图像内容作为数字数组

5. face_recognition人脸识别库使用示例代码:

import face_recognition
import cv2def show_landmarks(img, landmarks):for landmarks_dict in landmarks:for landmarks_key in landmarks_dict.keys():for point in landmarks_dict[landmarks_key]:cv2.circle(img, point, 2, (0, 0, 255), -1)cv2.imshow('img_landmarks', img)def show_locations(img, locations):for face_location in locations:# Print the location of each face in this imagetop, right, bottom, left = face_locationprint("A face is located at pixel location Top: {}, Left: {}, Bottom: {}, Right: {}".format(top, left, bottom, right))start = (left, top)  # 左上end = (right, bottom)  # 右下# 在图片上绘制矩形框,从start坐标开始,end坐标结束,矩形框的颜色为红色(0,255,255),矩形框粗细为2cv2.rectangle(img, start, end, (0, 255, 255), thickness=1)cv2.imshow('img_locations', img)# 1.读取图片
# 将图像文件(.jpg、.png等)加载到numpy数组中
image_origin = face_recognition.load_image_file("obama.jpg")
# cv2.imshow('image_origin', image_origin)  # 原始图片展示 BGR 格式# 2.格式转换
# 该face_recognition库仅支持 BGR 格式的图像,在打印输出图像时,我们应该使用 OpenCV 将其转换为 RGB。
img_rgb = cv2.cvtColor(image_origin, cv2.COLOR_BGR2RGB)
cv2.imshow('img_rgb', img_rgb)  # 展示 RGB 格式图片img_copy = img_rgb.copy()  # 避免形参对实参的影响# 3.通过face_recognition.face_landmarks()方法读取人脸关键点
# 返回人脸特征位置(眼睛、鼻子等)的字典列表
face_landmarks_list = face_recognition.face_landmarks(img_rgb)# show_landmarks(img_copy, face_landmarks_list)  # 在人脸上绘制关键点进行展示# 4.通过face_recognition.face_locations()方法获得人脸边框
# 返回图像中人脸的边界框数组 按 css 顺序(上、右、下、左)找到的人脸位置的元组列表
face_locations = face_recognition.face_locations(img_rgb)
print("I found {} face(s) in this photograph.".format(len(face_locations)))# show_locations(img_copy, face_locations)# 5.通过face_recognition.face_encodings()方法获得人脸编码
# 给定一个图像,返回图像中每个人脸的 128 维人脸编码。
list_of_face_encodings = face_recognition.face_encodings(img_rgb, known_face_locations=face_locations)# 6.通过face_recognition.api.compare_faces()方法获得人脸匹配结果
# 将人脸编码列表与候选编码进行比较,以查看它们是否匹配
# (known_face_encodings、face_encoding_to_check、公差=0.6)
test = face_recognition.load_image_file('biden.jpg')
test = cv2.cvtColor(test, cv2.COLOR_BGR2RGB)
cv2.imshow('test', test)test_encode = face_recognition.face_encodings(test)[0]
print(face_recognition.compare_faces([list_of_face_encodings], test_encode))  # 获取经过训练的编码列表和未知图像的测试编码。# 7.通过face_recognition.face_distance()方法获取每个比较人脸的欧氏距离
# 给定人脸编码列表,将它们与已知人脸编码进行比较,并获取每个比较人脸的欧氏距离。距离告诉您人脸的相似程度。距离越小越相似
face_distances = face_recognition.face_distance(list_of_face_encodings, test_encode)for i, face_distance in enumerate(face_distances):print("The test image has a distance of {:.2} from known image #{}".format(face_distance, i))print("- With a normal cutoff of 0.6, would the test image match the known image? {}".format(face_distance < 0.6))print("- With a very strict cutoff of 0.5, would the test image match the known image? {}".format(face_distance < 0.4))cv2.waitKey(0)

Face Recognition 库-人脸识别相关推荐

  1. 深度学习——Face Verificaton(人脸验证)与Face Recognition(人脸识别)在FaceNet的应用案例

    一.综述 人脸识别领域主要有两个范畴:Face Verificaton(人脸验证)与Face Recognition(人脸识别) 1.Face Verificaton(人脸验证):1:1的匹配问题.如 ...

  2. 共有65款 计算机视觉库/人脸识别开源软件

    转载:https://www.cnblogs.com/Anita9002/p/5038533.html. 引自:http://www.oschina.net/project/tag/316/openc ...

  3. 计算机视觉库/人脸识别开源软件

    中文车牌识别系统 EasyPR EasyPR 是一个开源的中文车牌识别系统. EasyPR是一个中文的开源车牌识别系统,其目标是成为一个简单.灵活.准确的车牌识别引擎. 相比于其他的车牌识别系统,Ea ...

  4. PCA实验人脸库-人脸识别(四)

    一):人脸数据库 AR人脸库(包含50位男性和50位女性每人26张人脸共2600张人脸图片 ): http://www.datatang.com/data/46195 ORL人脸库(包含40个人的每人 ...

  5. linux开源人脸识别库,人脸识别身份验证 HIDL

    概览 借助人脸识别身份验证功能,用户只需将自己的面孔对准设备即可将其解锁.Android 10 增加了对一种新的人脸识别身份验证堆栈的支持,这种堆栈可安全处理摄像头帧,从而在支持的硬件上进行人脸识别身 ...

  6. Python的开源人脸识别库:离线识别率高达99.38%【源码】

    以往的人脸识别主要是包括人脸图像采集.人脸识别预处理.身份确认.身份查找等技术和系统.现在人脸识别已经慢慢延伸到了ADAS中的驾驶员检测.行人跟踪.甚至到了动态物体的跟踪.由此可以看出,人脸识别系统已 ...

  7. 人脸识别(face recognition)

    一.前述 1. 发展 以往的人脸识别主要是包括人脸图像采集.人脸识别预处理.身份确认.身份查找等技术和系统.现在人脸识别已经慢慢延伸到了ADAS中的驾驶员检测.行人跟踪.甚至到了动态物体的跟踪.由此可 ...

  8. 人脸识别:Deep Face Recognition论文阅读

    基本概念 在具体到人脸识别方法之前,先对人脸识别中的Face detection, Face alignment, Face verification和Face identification(reco ...

  9. 一文读懂:深扒人脸识别60年技术发展史

    来源:与非网 摘要: "他来听我的演唱会,门票换了手铐一对".最近歌神张学友变阿SIR,演唱会上频频抓到罪犯,将人脸识别技术又一次推到了大众的视线中. "他来听我的演唱会 ...

  10. 人脸识别python face_recognize_【python+face_recognition】人脸识别初始

    [python+face_recognition]人脸识别初始 发布时间:2018-09-01 12:03, 浏览次数:366 , 标签: python face recognition face_r ...

最新文章

  1. 恩布企业IM,协同办公平台发布V1.24.2版本
  2. springcloud gateway 源码解析、请求响应流程、第三方响应结果在 gateway 的经过
  3. Makefile学习之通配符和自动变量
  4. 6、使用infowindow
  5. 有的时候看项目,和创业者交流,发现他们的企业
  6. Visualizing and Understanding Convolutional Networks论文解读
  7. Oracle12c用户名scott,Oracle12c新特性pdborcl,如何登录到普通用户scott ?
  8. SAP系统中资产的分类规则
  9. matlab绘制符号函数的ezplot函数
  10. 我的个人学习的小总结
  11. nyoj-975-关于521
  12. [朝气蓬勃][22H2]Win11.0.22622.450专工-微创-优化
  13. Acitivity的生命周期
  14. 51单片机,时钟频率,机器周期,与执行指令的时间
  15. 科学计算库学习笔记(持续更新)
  16. linux如何kill僵尸进程,linux 如何杀死僵尸进程——原理及操作
  17. SQL2008附加数据库时出错的解决办法
  18. Apache中如何设置网站默认首页
  19. Java八个基本数据类型所占字节数
  20. 【目标检测】常用概念AP和mAP

热门文章

  1. java删除浏览器cookies_清除浏览器cookie
  2. ffplay播放摄像头
  3. 现代电工技术实训考核装置
  4. Linux下tomcat修改端口(80)
  5. matlab2018A配置cuda,使用教程 | matlab 2018a + cuda 10.1 + vs 2017
  6. Mac最好用的RSS阅读器Reeder使用方法
  7. Python3之pip加速
  8. 51单片机蓝牙模块的使用方法
  9. 360杀毒软件安装在windows2003系统的解决方法
  10. java性能调优寻找瓶颈常用的命令_Java性能调优:利用VisualVM进行性能分析