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库的介绍请查看以下链接

相关文章

关于numpy中eye和identity的区别详解

两个函数的原型为: np.identity(n, dtype=None) np.eye(N, M=None, k=0, dtype=<type ‘float'>); np.i...

python pandas库的安装和创建

python pandas库的安装和创建

pandas 对于数据分析的人员来说都是必须熟悉的第三方库,pandas 在科学计算上有很大的优势,特别是对于数据分析人员来说,相当的重要。python中有了Numpy ,但是Numpy...

Python中定时任务框架APScheduler的快速入门指南

前言 大家应该都知道在编程语言中,定时任务是常用的一种调度形式,在Python中也涌现了非常多的调度模块,本文将简要介绍APScheduler的基本使用方法。 一、APScheduler...

一个基于flask的web应用诞生 bootstrap框架美化(3)

一个基于flask的web应用诞生 bootstrap框架美化(3)

经过上一章的内容,其实就页面层来说已结可以很轻松的实现功能了,但是很明显美观上还有很大的欠缺,现在有一些很好的前端css框架,如AmazeUI,腾讯的WeUI等等,这里推荐一个和flas...

python+influxdb+shell编写区域网络状况表

python+influxdb+shell编写区域网络状况表

本文为大家分享了python+influxdb+shell写一个区域网络状况表,供大家参考,具体内容如下 shell脚本部分: ex:就是ping 各个目的ip10个包,然后获取丢包率...