脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - Python人脸识别第三方库face_recognition接口说明文档

Python人脸识别第三方库face_recognition接口说明文档

2021-06-23 00:09WDC Python

Python人脸识别第三方库face_recognition接口简单说明,及简单使用方法

1. 查找图像中出现的人脸

代码示例:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#导入face_recognition模块
 
import face_recognition
 
#将jpg文件加载到numpy数组中
 
image = face_recognition.load_image_file(“your_file.jpg”)
 
#查找图片中人脸(上下左右)的位置,图像中可能有多个人脸
 
#face_locations的值类似[(135,536,198,474),()]
 
face_locations = face_recognition.face_locations(image);
 
# 使用cnn模型 准确率高
 
face_locations = face_recognition.face_locations(image, number_of_times_to_upsample=0, model="cnn")
 
face_locations = face_recognition.face_locations(small_frame, model="cnn")

2. 获取图像中人脸的眼睛、鼻子、嘴、下巴、眉毛的位置和轮廓

代码示例:

?
1
2
3
4
5
6
7
8
9
import face_recognition
 
image = face_recognition.load_image_file(“your_file.jpg”)
 
#查找图片中人脸的所有面部特征(眉毛,眼睛,鼻子,上下嘴唇,面部轮廓)
 
#face_landmarks_list是个二维数组
 
face_landmarks_list = face_recognition.face_landmarks(image)

3. 识别图像中出现的人脸 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import face_recognition
 
known_image = face_recognition.load_image_file(“biden.jpg”)
 
unknown_imag = face_recognition.load_image_file(“unknown.jpg”)
 
#获取每个图像文件中每个面部的面部编码
 
#由于每个图像中可能有多个人脸,所以返回一个编码列表。
 
#但是事先知道每个图像只有一个人脸,每个图像中的第一个编码,取索引0。
 
biden_encoding =face_recognition.face_encodings(known_image)[0]
 
unknown_encoding=face_recognition.face_encodings(unknown_image)[0]
 
#如果图像中有多个人脸 获取图像中多个人脸编码
 
face_locations = face_recognition.face_locations(unknow_image)
 
face_encodings = face_recognition.face_encodings(unknown_image, face_locations)
 
#结果是true/false的数组,未知面孔known_faces阵列中的任何人相匹配的结果
 
#[true, false,false]
 
results=face_recognition.compare_faces([biden_encoding],unknown_encoding)
 
#结果是true/false的数组,未知面孔known_faces阵列中的任何人相匹配的结果 设定比对结果的阀值
 
#[true, false,false]
 
 match = face_recognition.compare_faces(known_faces, face_encoding, tolerance=0.50)

4.两个人脸的相似度

?
1
2
3
4
5
6
7
#结果是小于1的值 例如0.5 0.7等
 
face_distances = face_recognition.face_distance(known_encodings, image_to_test_encoding)
 
设定阀值 05或者0.6
 
face_distances < 阀值

更多关于face_recognition库的介绍请查看以下链接

原文链接:https://blog.csdn.net/u010471273/article/details/80682638

延伸 · 阅读

精彩推荐