当前位置:网站首页>人脸检测和识别--face recognition包
人脸检测和识别--face recognition包
2022-08-03 05:41:00 【茫茫人海一粒沙】
环境准备
pip install cmake
pip install dlib==19.8.1
pip install face_recognition
pip install opencv-python人脸检测
代码
提取图片中人脸的位置
import face_recognition
image = face_recognition.load_image_file("your_file.jpg")
face_locations = face_recognition.face_locations(image)结果
[(297, 810, 759, 348)]
完整代码
import face_recognition
import cv2
from matplotlib import pyplot as plt
image = cv2.imread("test1.jpeg")
# image = face_recognition.load_image_file("test1.jpeg")
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image_orign = image.copy()
face_locations = face_recognition.face_locations(image)
for (top, right, bottom, left) in face_locations:
image = cv2.rectangle(image, (left, top), (right, bottom), (0, 0, 255), 2)
plt.subplot(1, 2, 1)
plt.imshow(image_orign)
plt.subplot(1, 2, 2)
plt.imshow(image)
plt.show()
人脸中具体部分的位置
import face_recognition
image = face_recognition.load_image_file("your_file.jpg")
face_landmarks_list = face_recognition.face_landmarks(image)结果
[{'chin': [(299, 533), (316, 592), (337, 648), (367, 696), (410, 733), (463, 758), (520, 778), (574, 790), (618, 785), (649, 763), (668, 725), (688, 686), (707, 644), (719, 599), (725, 551), (723, 502), (713, 454)], 'left_eyebrow': [(375, 465), (405, 431), (450, 409), (501, 403), (549, 414)], 'right_eyebrow': [(590, 411), (618, 390), (648, 380), (679, 383), (700, 401)], 'nose_bridge': [(574, 471), (585, 504), (596, 537), (608, 571)], 'nose_tip': [(568, 613), (587, 614), (606, 615), (620, 606), (633, 594)], 'left_eye': [(429, 503), (453, 483), (482, 478), (510, 495), (485, 504), (456, 508)], 'right_eye': [(612, 476), (629, 450), (654, 443), (675, 454), (661, 468), (636, 474)], 'top_lip': [(540, 694), (571, 668), (595, 650), (612, 651), (624, 642), (643, 647), (658, 661), (647, 662), (626, 660), (614, 665), (598, 669), (555, 689)], 'bottom_lip': [(658, 661), (649, 680), (636, 694), (622, 701), (604, 705), (577, 705), (540, 694), (555, 689), (601, 675), (617, 672), (630, 666), (647, 662)]}]人脸识别
代码
那你要识别的人脸照片与检测出来的照片做一个对比,如果自信度高,就是你要找的人脸
import face_recognition
known_image = face_recognition.load_image_file("me.jpg")
unknown_image = face_recognition.load_image_file("unknown.jpg")
biden_encoding = face_recognition.face_encodings(known_image)[0]
unknown_encoding = face_recognition.face_encodings(unknown_image)[0]
results = face_recognition.compare_faces([biden_encoding], unknown_encoding)总结
人脸检测没有MTCNN好,人脸的小的时候就检测不出来了。或者模糊的时候也检测不出来。
下图可以看出第三个人的脸没检测出来,这种例子很多,你们可以试一试。

参考资料
边栏推荐
猜你喜欢

Getting started with el-tabs (tab bar)

Flink的Exactly-Once、状态机制、watermark机制

El - tree set using setCheckedNodessetCheckedKeys default check nodes, and a new check through setChecked specified node

el-table实现列筛选功能,控制列的显示和隐藏(实现简单,效果满分)

超全!9种PCB表面处理工艺大对比

【playwright】pytest-playwright增加代理服务选项

sql优化常用的几种方法

Docker安装Mysql

Shell脚本--信号发送与捕捉

MySQL必知必会
随机推荐
2021年PHP-Laravel面试题问卷题 答案记录
【OpenStack云平台】搭建openstack云平台
MySQL 操作语句大全(详细)
微信小程序 - 监听 TabBar 切换点击事件
【云原生 · Kubernetes】Kubernetes基础环境搭建
MySQL的 DDL和DML和DQL的基本语法
el-tabs(标签栏)的入门学习
el-tree设置利用setCheckedNodessetCheckedKeys默认勾选节点,以及通过setChecked新增勾选指定节点
ClickHouse 数据插入、更新与删除操作 SQL
PCB板上的字母代表哪些元器件?一文看全!
nvm 卸载详细流程
PostMan测试接口-----上传文件、导出excel
【经验分享】配置用户通过Console口登录设备示例
Pinned Articles-
CCF NOI 2022笔试题库
pyspark --- 空串替换为None
el-table获取读取数据表中某一行的数据属性
Composer require 报错 Installation failed, reverting ./composer.json and ./composer.lock to their ...
Content type ‘applicationx-www-form-urlencoded;charset=UTF-8‘ not supported“【已解决】
502 bad gateway原因、解决方法
