【人脸识别】face_recognition 库的使用
目录
- 1. load_image_file 加载图像
- 2. face_locations 定位图中所有人脸
- (1)在原图像中框出人脸
- (2)剪切出人脸
- 3. face_landmarks 识别人脸关键点
1. load_image_file 加载图像
- 输出图像是 RGB 格式(opencv中是 BGR 格式)
- 图像类型是 ndarray
import face_recognitionimage = face_recognition.load_image_file("image.jpeg") # 读取图像
print(image.shape) # (3073, 2048, 3)
print(type(image)) # <class 'numpy.ndarray'>
2. face_locations 定位图中所有人脸
函数作用:识别出图像中所有人脸,并以列表的形式返回人脸的位置信息
函数输出:输出一个列表,形如: [(411, 956, 540, 827), (283, 605, 390, 497)]
- 列表中包含两个tuple (411, 956, 540, 827) 和 (283, 605, 390, 497) ,表示识别出了两个人脸
- 每个 tuple 中的4个数字表示这个人脸的位置信息,分别为 [top, right, bottm,left] , 代表框住人脸的矩形中左上角位置坐标 (left, top)和右下角的位置坐标(right, bottom)
import face_recognition
import cv2image = face_recognition.load_image_file("image.jpeg") # 读取图像
face_locations = face_recognition.face_locations(image) # 获取人脸位置
print(face_locations)
输出:
[(990, 1347, 1311, 1026), (491, 1133, 812, 812), (1895, 1152, 2163, 884)]
检测到的第一个人脸位置坐标(990, 1347, 1311, 1026),对应如下
(1)在原图像中框出人脸
import face_recognition
import cv2image = face_recognition.load_image_file("image.jpeg") # 读取图像
face_locations = face_recognition.face_locations(image) # 获取人脸位置
print(face_locations)# ---------------------------------------------------
img = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
for p in face_locations:print(p)face_detect = cv2.rectangle(img, (p[3], p[0]), (p[1], p[2]), (0, 0, 255), 5)cv2.imshow('face_detect'.format(), face_detect)
cv2.waitKey()
cv2.destroyAllWindows()
(2)剪切出人脸
import face_recognition
import cv2image = face_recognition.load_image_file("image.jpeg") # 读取图像
face_locations = face_recognition.face_locations(image) # 获取人脸位置
print(face_locations) # [(411, 956, 540, 827), (283, 605, 390, 497)]img = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)for i, p in enumerate(face_locations):face_detect = img[p[0]:p[2], p[3]:p[1]]cv2.imshow('face_detect_{}'.format(i), face_detect)cv2.waitKey()
cv2.destroyAllWindows()
3. face_landmarks 识别人脸关键点
- 函数作用:识别出 9种人脸关键点信息 ,包括眼睛、鼻子、嘴巴和下巴等
- 返回值:是个list,列表长度表示有几个人的面部信息;list 中的项是字典,每个字典的key表示面部特征的名字,值为这个面部特征的位置信息(是一个列表); 特征点包括:
- nose_bridge
- right_eyebrow
- right_eye
- chine
- left_eyebrow
- bottom_lip
- nose_tip
- top_lip
- left_eye
import face_recognition
import cv2
import numpy as npimage = face_recognition.load_image_file("image.jpeg") # 读取图像
face_landmarks_list = face_recognition.face_landmarks(image) # 获取人脸位置img = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
for face_landmarks in face_landmarks_list:facial_features = ['left_eye','right_eye','nose_tip','top_lip','bottom_lip']# 在图像中画出每个人的眼睛, 鼻子, 嘴巴!for facial_feature in facial_features:points = np.array(face_landmarks[facial_feature])cv2.polylines(img, [points], False, (0, 0, 255), 2)cv2.imshow('facial_feature', img)
cv2.waitKey()
cv2.destroyAllWindows()
【人脸识别】face_recognition 库的使用相关推荐
- 人脸识别开源库face_recognition的简单介绍
人脸识别开源库face_recognition的简单介绍 原文出处: https://blog.xugaoxiang.com/ai/face-recognition-cnn.html 软硬件环境 ub ...
- Mac/Linux安装人脸识别常用库(tensorflow、pytorch、dlib、face_recognition、opencv、CMake、gcc/g++)————所有环境一次性配置好
文章目录 0 背景与准备 1 tensorflow环境[数值计算的开源软件库] 2 pytorch环境[数值计算的开源软件库] 3 face_recognition[基于dlib的人脸识别库] 4 o ...
- 机器学习之人脸识别face_recognition使用
机器学习之人脸识别face_recognition使用 简介 一 二 主要方法介绍 1. load_image_file 加载图像 2. face_locations 定位图中所有人脸 3. face ...
- 人脸识别开源库face_recognition
原文出处: https://blog.xugaoxiang.com/ai/face-recognition-cnn.html 软硬件环境 ubuntu 18.04 64bit GTX 1070Ti a ...
- 人脸识别用哪种python库_Python人脸识别第三方库face_recognition接口介绍文档
1. 查找图像中出现的人脸 代码示例: #导入face_recognition模块 import face_recognition #将jpg文件加载到numpy数组中 image = face_re ...
- 人脸识别dlib库 记录
暑假和大佬报了一个比赛,因为最近在学python所以我们报了Python组的人脸识别.对于人脸识别来说Python有face_recognition库,经过网上查找资料以及官方文档我们很快就完成了.不 ...
- face.evoLVe:高性能人脸识别开源库,内附高能模型
点击我爱计算机视觉标星,更快获取CVML新技术 目前人脸识别开源项目众多,但真正能方便快捷拿来就用.性能指标业界领先的开源库并不多,而最近刚刚开源的face.evoLVe绝对是不容忽视的力量. 项目地 ...
- AI识别照片是谁,人脸识别face_recognition开源项目安装使用 | 机器学习
目录 前言 环境安装 代码使用 总结 前言 最近碰到了照片识别的场景,正好使用了face_recognition项目,给大家分享分享.face_recognition项目能做的很多,人脸检测功能也是有 ...
- matlab人脸识别样本库建立,facenet 人脸识别(二)——创建人脸库搭建人脸识别系统...
搭建人脸库 选择的方式是从百度下载明星照片 照片下载,downloadImageByBaidu.py # coding=utf-8 """ 爬取百度图片的高清原图 &qu ...
- 好玩的人脸识别face_recognition安装+尝试+API详细
face_recognition是一个可玩度很高的人脸识别开源框架,不仅安装方便,运行起来也很轻松. 官网:https://github.com/ageitgey/face_recognition.g ...
最新文章
- POJ 3667 Hotel(线段树)
- vivado与modelsim的联合仿真(一)
- Android学习日记(1)
- python学习-综合练习二(整数和浮点数判断奇偶、质数判断)
- libreoffice Error: source file could not be loaded
- java找出两个List集合的重复项
- 用MSBuild.... DailyBuild和软件开发流程的东东
- windows10更新后网络无法连接的问题
- 在Win10中通过Google Chrome运行安卓应用
- mysql存大日志_MySQL三大日志
- 2021-04-26 Matlab遗传算法工具箱的使用及实例(线性规划)
- 安卓玩java模拟器_安卓系统智能手机玩JAVA游戏!JAVA模拟器让你痛快地玩!
- 戴尔笔记本电脑耳机插入声音外放问题
- 三次样条插值详解(附代码实现)
- 谁来救救过拟合?透过现象看本质,如何利用正则化方法解决过拟合问题
- 重装 UOS Deepin V20 后必安装软件(个人习惯)
- Android截屏分享
- python中将科学计数法转数字
- UnityWebPlayer屏蔽右键及全屏
- 2017 Google I/O 最新科技看点