Dome 多人人脸识别 face_recognition

注意

face_recognition 依赖 face_recognition_models

中文字体文件需要自己下载

1.多人人脸识别

# 多人 人脸识别
import os
import numpy as np
import face_recognition
from PIL import Image, ImageDraw, ImageFont PATH = 'face_imgs'
TMP_IMG = 'tt4.jpeg' # 制作所有可用图像特征码列表
dirs = os.listdir(PATH)
names = [i.split('.')[0] for i in dirs]
face_codes = [] for img_dir in dirs:
current_image = face_recognition.load_image_file(f'{PATH}/{img_dir}')
face_codes.append(face_recognition.face_encodings(current_image)[0]) # 读取目标图片并识别人脸
image = face_recognition.load_image_file(TMP_IMG) pil_image = Image.fromarray(image)
d = ImageDraw.Draw(pil_image) # 定位所有找到的脸的位置
face_locations = face_recognition.face_locations(image)
# 循环找到的所有人脸 results = []
for face_location in face_locations: # 打印每张脸的位置信息
top, right, bottom, left = face_location
# 抠人脸图
face_image = image[top:bottom, left:right]
# 求特征码
# o_face_code.append(face_recognition.face_encodings(np.array(face_image))[0])
result = face_recognition.compare_faces(face_codes,
face_recognition.face_encodings(np.array(face_image))[0],
tolerance=0.4)
results.append(result)
# 画矩形
d.rectangle((left, top, right, bottom), None, 'red', width=2)
# 画文字_中文 name = ''
for na in np.unique(np.array(names)[result]):
name += f'{na} '
path_to_ttf = r'font/simfang.ttf'
font = ImageFont.truetype(path_to_ttf, size=14) # 设置字体
d.text(xy=(left, bottom), text=name, fill='red', font=font, stroke_width=1) pil_image.show()

2.人脸检测

from PIL import Image, ImageDraw

import face_recognition

# 读取图片并识别人脸
image = face_recognition.load_image_file("t2.png")
face_locations = face_recognition.face_locations(image)
print(face_locations) pil_image = Image.fromarray(image)
d = ImageDraw.Draw(pil_image) # 遍历每个人脸,并标注
faceNum = len(face_locations)
for i in range(0, faceNum):
top = face_locations[i][0]
right = face_locations[i][1]
bottom = face_locations[i][2]
left = face_locations[i][3] rect = (left, top, right, bottom) d.rectangle(rect, None, outline='red', width=2) pil_image.show()

3.人脸检测加抠图

from PIL import Image

import face_recognition
#加载图像文件
image = face_recognition.load_image_file("t2.png") #定位所有找到的脸的位置
face_locations = face_recognition.face_locations(image)
# 循环找到的所有人脸
for face_location in face_locations:
# 打印每张脸的位置信息
top, right, bottom, left = face_location
print("A face is located at pixel location Top: {}, Left: {}, Bottom: {}, Right: {}".format(top, left, bottom, right))
# 指定人脸的位置信息,然后显示人脸图片
face_image = image[top:bottom, left:right]
pil_image = Image.fromarray(face_image)
pil_image.show()

4.关键点检查

from PIL import Image, ImageDraw
import face_recognition # 将jpg文件加载到numpy 数组中
image = face_recognition.load_image_file("t2.png") #查找图像中所有面部的所有面部特征
face_landmarks_list = face_recognition.face_landmarks(image) print("I found {} face(s) in this photograph.".format(len(face_landmarks_list)))
pil_image = Image.fromarray(image) d = ImageDraw.Draw(pil_image)
for face_landmarks in face_landmarks_list:
#打印此图像中每个面部特征的位置
facial_features = [
'chin',
'left_eyebrow',
'right_eyebrow',
'nose_bridge',
'nose_tip',
'left_eye',
'right_eye',
'top_lip',
'bottom_lip'
]
for facial_feature in facial_features:
print("The {} in this face has the following points: {}".format(facial_feature, face_landmarks[facial_feature]))
#在图像中画出每个人脸特征!
for facial_feature in facial_features:
d.line(face_landmarks[facial_feature], width=2, fill='red') pil_image.show()

5.关键点检查加毁容

** 据说是美颜来着,怎么成这样我也......emmmmmm**

import face_recognition
from PIL import Image, ImageDraw # Load the jpg file into a numpy array
image = face_recognition.load_image_file("tt3.jpg") # Find all facial features in all the faces in the image
face_landmarks_list = face_recognition.face_landmarks(image) for face_landmarks in face_landmarks_list:
# Create a PIL imageDraw object so we can draw on the picture
pil_image = Image.fromarray(image)
d = ImageDraw.Draw(pil_image, 'RGBA') # 画个浓眉
d.polygon(face_landmarks['left_eyebrow'], fill=(68, 54, 39, 128))
d.polygon(face_landmarks['right_eyebrow'], fill=(68, 54, 39, 128))
d.line(face_landmarks['left_eyebrow'], fill=(68, 54, 39, 150), width=5)
d.line(face_landmarks['right_eyebrow'], fill=(68, 54, 39, 150), width=5) # 涂个性感的嘴唇
d.polygon(face_landmarks['top_lip'], fill=(150, 0, 0, 128))
d.polygon(face_landmarks['bottom_lip'], fill=(150, 0, 0, 128))
d.line(face_landmarks['top_lip'], fill=(150, 0, 0, 64), width=8)
d.line(face_landmarks['bottom_lip'], fill=(150, 0, 0, 64), width=8) # 闪亮的大眼睛
d.polygon(face_landmarks['left_eye'], fill=(255, 255, 255, 30))
d.polygon(face_landmarks['right_eye'], fill=(255, 255, 255, 30)) # 画眼线
d.line(face_landmarks['left_eye'] + [face_landmarks['left_eye'][0]], fill=(0, 0, 0, 110), width=6)
d.line(face_landmarks['right_eye'] + [face_landmarks['right_eye'][0]], fill=(0, 0, 0, 110), width=6) pil_image.show()

原图













Dome 多人人脸识别 face_recognition的更多相关文章

  1. Python 人工智能之人脸识别 face_recognition 模块安装

    Python人工智能之人脸识别face_recognition安装 face_recognition 模块使用系统环境搭建 系统环境 Ubuntu / deepin操作系统 Python 3.6 py ...

  2. 可学习的多人人脸识别程序(基于Emgu CV)

    源代码下载(需要安装Emgu CV,安装方法请百度) 很多朋友使用Emgu CV遇到CvInvoke()的报错,我找到一种解决方法. 把EmguCV目录下bin里面的所有dll复制到C:\WINDOW ...

  3. 开源人脸识别face_recognition

    环境:python36 1.安装dlib.face_recognition windows版 下载dlib,cp后面是py版本 下载地址:https://pypi.org/simple/dlib/ 提 ...

  4. opencv学习之路(41)、人脸识别

    一.人脸检测并采集个人图像 //take_photo.cpp #include<opencv2/opencv.hpp> using namespace cv; using namespac ...

  5. 手把手教你用1行代码实现人脸识别 --Python Face_recognition

    环境要求: Ubuntu17.10 Python 2.7.14 环境搭建: 1. 安装 Ubuntu17.10 > 安装步骤在这里 2. 安装 Python2.7.14 (Ubuntu17.10 ...

  6. face_recognition开源人脸识别库:离线识别率高达99.38%

    基于Python的开源人脸识别库:离线识别率高达99.38%——新开源的用了一下感受一下 原创 2017年07月28日 21:25:28 标签: 人脸识别 / 人脸自动定位 / 人脸识别开源库 / f ...

  7. Github开源人脸识别项目face_recognition

    Github开源人脸识别项目face_recognition 原文:https://www.jianshu.com/p/0b37452be63e 译者注: 本项目face_recognition是一个 ...

  8. 基于Python的face_recognition库实现人脸识别

    一.face_recognition库简介 face_recognition是Python的一个开源人脸识别库,支持Python 3.3+和Python 2.7.引用官网介绍: Recognize a ...

  9. 利用face_recognition,dlib与OpenCV调用摄像头进行人脸识别

    用已经搭建好 face_recognition,dlib 环境来进行人脸识别 未搭建好环境请参考:https://www.cnblogs.com/guihua-pingting/p/12201077. ...

随机推荐

  1. fsLayuiPlugin数据字典使用

    概述 数据字典主要解决下拉框数据填充和数据表格转义处理,一个数据字典可以多处使用. 1.多个页面下拉框使用同样的数据,改一个地方需要把所有页面都要修改 2.数据表格转义代替自己手动写templet解析 ...

  2. Windows SMBv3 CVE-2020-0796漏洞

    今天,Microsoft不小心泄露了有关新产品的信息 蠕虫的 Microsoft服务器消息块(SMB)协议中的漏洞(CVE-2020-0796). 今天,Microsoft不小心泄露了有关安全更新的信 ...

  3. vue中eslint报错的解决方案

    1,Newline required at end of file but not found. (eol-last) //文末需要一行 这个是报错: 这个是不报错的: 只需要在最后一行加上一空行即可 ...

  4. 爬取疫情数据,以django+pyecharts实现数据可视化web网页

    在家呆着也是呆着,不如做点什么消磨时间呗~ 试试用django+pyecharts实现疫情数据可视化web页面 这里要爬疫情数据 来自丁香园.搜狗及百度的疫情实时动态展示页 先看看劳动成果: 导航栏: ...

  5. 数据结构 5 哈希表/HashMap 、自动扩容、多线程会出现的问题

    上一节,我们已经介绍了最重要的B树以及B+树,使用的情况以及区别的内容.当然,本节课,我们将学习重要的一个数据结构.哈希表 哈希表 哈希也常被称作是散列表,为什么要这么称呼呢,散列.散列.其元素分布较 ...

  6. MongoDB复制集概念架构浅析

    一.复制集的作用 (1) 高可用 防止设备(服务器.网络)故障. 提供自动failover 功能. 技术来保证数 (2) 灾难恢复 当发生故障时,可以从其他节点恢复. (3) 功能隔离 用于分析.报表 ...

  7. 原来rollup这么简单之 rollup.rollup篇

    大家好,我是小雨小雨,致力于分享有趣的.实用的技术文章. 内容分为翻译和原创,如果有问题,欢迎随时评论或私信,希望和大家一起进步. 分享不易,希望能够得到大家的支持和关注. 计划 rollup系列打算 ...

  8. 洛谷P1000超级马里奥的神奇解法

    话说上过洛谷的都知道,有一道经典例题P1000超级马里奥,这一题,可以说是非常简单非常经典,但是就算如此,还是可以人才辈出,我是个比较循规蹈矩的人(雾),所以我的代码就比较平常,也就是直接输出了所要求 ...

  9. css中:overflow:hidden清除浮动的原理

    要想彻底清除浮动的影响,适合的属性不是 clear 而是 overflow. 一般使用 overflow:hidden,利用 BFC 的“结界”特性彻底解决浮动对外部或兄弟元素的影响. 1. 前言: ...

  10. 建议13:禁用Function构造函数

    定义函数的方法包括3种:function语句,Function构造函数和函数直接量.不管用哪种方法定义函数,它们都是Function对象的实例,并将继承Function对象所有默认或自定义的方法和属性 ...