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

yipeiwu_com5年前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 访问限制 private public的详细介绍

 一、知识点 在一个模块中,我们可能会定义很多函数和变量。但有的函数和变量我们希望能给别人使用,有的函数和变量我们希望仅仅在模块内部使用,so? 我们可以通过定义该函...

python+unittest+requests实现接口自动化的方法

python+unittest+requests实现接口自动化的方法

前言: Requests简介 Requests 是使用Apache2 Licensed 许可证的 HTTP 库。用 Python 编写,真正的为人类着想。 Python 标准库中的 ur...

21行Python代码实现拼写检查器

引入 大家在使用谷歌或者百度搜索时,输入搜索内容时,谷歌总是能提供非常好的拼写检查,比如你输入 speling,谷歌会马上返回 spelling。 下面是用21行python代码实现的一...

pip安装Python库时遇到的问题及解决方法

pip安装Python库时遇到的问题及解决方法

笔者电脑系统是win7,同时安装了Python2.7和Python3.6,但是在通过命令行直接使用“pip install XXX”安装Python库时出现了以下的错误信息: Fatal...

Python变量、数据类型、数据类型转换相关函数用法实例详解

Python变量、数据类型、数据类型转换相关函数用法实例详解

本文实例讲述了Python变量、数据类型、数据类型转换相关函数用法。分享给大家供大家参考,具体如下: python变量的使用不需要进行类型声明(类型名 变量名),给一个变量名赋什么值就是...