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

yipeiwu_com6年前Python基础

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

代码示例:

#导入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. 获取图像中人脸的眼睛、鼻子、嘴、下巴、眉毛的位置和轮廓

代码示例:

import face_recognition

image = face_recognition.load_image_file(“your_file.jpg”)

#查找图片中人脸的所有面部特征(眉毛,眼睛,鼻子,上下嘴唇,面部轮廓)

#face_landmarks_list是个二维数组

face_landmarks_list = face_recognition.face_landmarks(image)

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

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的值 例如0.5 0.7等

face_distances = face_recognition.face_distance(known_encodings, image_to_test_encoding)

设定阀值 05或者0.6等

face_distances < 阀值

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

相关文章

Python 含参构造函数实例详解

本篇博文主要介绍在Python3中如何构造含参构造函数 样例如下: class MyOdlHttp: username = '' password = '' def _...

linux下python使用sendmail发送邮件

本文实例为大家分享了python使用sendmail发送邮件的具体代码,供大家参考,具体内容如下 参考链接:How do I send mail from a Python script...

python实现屏保程序(适用于背单词)

python实现屏保程序(适用于背单词)

今天要给大家分享的是一款自己写的屏保程序,大学大家最头疼的就是四六级的考试了,上次考试做阅读的时候,情不自禁的发呆,想着如果我能在电脑上写一个屏保程序,那么就可以天天记单词了! 开始 首...

centos 下面安装python2.7 +pip +mysqld

python2.7 复制代码 代码如下: wget http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz yum inst...

对python append 与浅拷贝的实例讲解

在做Leetcode的第39题的时候,看到网上一个用递归的解法,很简洁。于是重写了一遍。 class Solution(object): def combinationSum(se...