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函数进行模块化的实现

使用 Python 函数来最大程度地减少重复任务编码工作量。 你是否对函数、类、方法、库和模块等花哨的编程术语感到困惑?你是否在与变量作用域斗争? 无论你是自学成才的还是经过正式培训的程...

Python 脚本拉取 Docker 镜像问题

Python 脚本拉取 Docker 镜像问题

好久没有介绍小工具了,今天碰到一个,简单粗糙但是有用的一个,这个工具有多简单粗糙呢?证据有二: 连 Python shebang 都没有; 简单到原创 300 字都很难凑够。 言归正传:...

python飞机大战pygame游戏之敌机出场实现方法详解

python飞机大战pygame游戏之敌机出场实现方法详解

本文实例讲述了python飞机大战pygame游戏之敌机出场实现方法。分享给大家供大家参考,具体如下: 目标 使用 定时器 添加敌机 设计 Enemy 类 01. 使用定时器添加...

pytorch中的上采样以及各种反操作,求逆操作详解

pytorch中的上采样以及各种反操作,求逆操作详解

import torch.nn.functional as F import torch.nn as nn F.upsample(input, size=None, scale_fact...

树莓派极简安装OpenCv的方法步骤

树莓派极简安装OpenCv的方法步骤

因为最近在开发使用树莓派+usb摄像头识别模块,打算用OpenCv,发现网上的树莓派OpenCv安装教程都过于繁琐占用内存大,我经过自己的实验,发现出了一种非常简易快捷的方式,网速OK的...