当前位置:网站首页>人脸检测和识别--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好,人脸的小的时候就检测不出来了。或者模糊的时候也检测不出来。
下图可以看出第三个人的脸没检测出来,这种例子很多,你们可以试一试。
参考资料
边栏推荐
猜你喜欢
MySQL的DATE_FORMAT()函数将Date转为字符串
关于NOI 2022的报到通知
MySQL的Replace用法详解
关于Attention的超详细讲解
Redis-记一次docker下使用redis
MySql的安装配置超详细教程与简单的建库建表方法
Docker安装Mysql
保姆级讲解Transformer
empty() received an invalid combination of arguments - got (tuple, dtype=NoneType, device=NoneType),
torch.nn.modules.activation.ReLU is not a Module subclass
随机推荐
Embedding two implementations of the torch code
流式低代码编程,拖拽节点画流程图并运行
HDI与普通PCB的4点主要区别
Composer require 报错 Installation failed, reverting ./composer.json and ./composer.lock to their ...
Cesium加载离线地图和离线地形
El - table column filter functions, control columns show and hide (effect and easy to implement full marks)
Nacos下载与安装
【干货分享】PCB 板变形原因!不看不知道
Mysql去除重复数据
MySQL的Replace用法详解
10 common data types in MySQL
一文读懂PCB品质体系认证
SQLServer2019安装(Windows)
empty() received an invalid combination of arguments - got (tuple, dtype=NoneType, device=NoneType),
spark中Repartition 和 Coalesce 区别
记一次postgresql中使用正则表达式
Autowired注解与Resource注解的区别
连续型特征做embedding代码示例
ClickHouse 数据插入、更新与删除操作 SQL
链表之打基础--基本操作(必会)