当前位置:网站首页>超级简单的人脸识别api 只需几行代码就可以实现人脸识别
超级简单的人脸识别api 只需几行代码就可以实现人脸识别
2022-07-23 05:37:00 【mandala -chen】
实验环境
这个库在原生python并在windows环境下,官方是不支持的
我是在anconda的环境下使用这个库 下面依次序安装下面三个包
pip install cmake
pip install dlib
pip install face_recognition
api说明
这个库的内容非常简单,但是已经能够覆盖人脸识别的基本功能配合其他库如Pillow和opencv的使用能够让这个库看起来异常强大
下面简单列出几个这个库的功能 更多的请参考库的官方文档
face_recognition.api.load_image_file(file,mode ='RGB' )
功能说明:
将图像文件(.jpg,.png等)加载到numpy数组中
face_recognition.api.batch_face_locations(images,number_of_times_to_upsample = 1,batch_size = 128 )
功能说明:
使用cnn人脸检测器返回图像中人脸边界框的2d数组。如果您使用的是GPU,由于GPU可以一次处理一批图像,因此可以更快地获得结果。如果您不使用GPU,则不需要此功能
face_recognition.api.face_distance(face_encodings,face_to_compare )
功能说明:
给定面部编码列表,将其与已知的面部编码进行比较,并获得每个比较面部的欧式距离。距离告诉您面孔的相似程度
face_recognition.api.face_distance(face_encodings,face_to_compare )
功能说明:
给定面部编码列表,将其与已知的面部编码进行比较,并获得每个比较面部的欧式距离。距离告诉您面孔的相似程度。
face_recognition.api.face_encodings(face_image,known_face_locations = None,num_jitters = 1,model ='small' )
功能说明:
给定图像,返回图像中每个面部的128维面部编码
face_recognition.api.face_landmarks(face_image,face_locations = None,model ='large' )
功能说明:
给定图像,返回图像中每个面部的面部特征位置(眼睛,鼻子等)的字典列表
face_recognition.api.face_locations(img,number_of_times_to_upsample = 1,model ='hog' )
功能说明:
返回图像中人脸边界框的数组
实例
这个qpi还在github上开源了很多例子
例如下面这个代码就是从一张照片中提取出人脸面部
from PIL import Image, ImageDraw,ImageFont
import face_recognition
image = face_recognition.load_image_file("/9k_.jpg")
face_locations = face_recognition.face_locations(image)
for face_location in face_locations:
# Print the location of each face in this image
top, right, bottom, left = face_location
print("A face is located at pixel location Top: {}, Left: {}, Bottom: {}, Right: {}".format(top, left, bottom, right))
# You can access the actual face itself like this:
face_image = image[top:bottom, left:right]
pil_image = Image.fromarray(face_image)
pil_image.show()
效果就是这样啦
边栏推荐
- Concepts et différences de bits, bits, octets et mots
- Two strategies for building AI products / businesses (by Andrew ng)
- Cadence (IX) 17.4 rules and spacing settings
- [untitled]
- Redis源码与设计剖析 -- 10.列表对象
- Recommend a shell installation force artifact, which has been open source! Netizen: really fragrant...
- 华为高层谈 35 岁危机,程序员如何破年龄之忧?
- Redis源码与设计剖析 -- 6.压缩列表
- 【视觉SLAM】ORB-SLAM: Tracking and Mapping Recognizable Features
- Activiti工作流使用之新建bpmn文件
猜你喜欢

The 12th Blue Bridge Cup embedded design and development project

Redis源碼與設計剖析 -- 7.快速列錶

【视觉SLAM】ORB-SLAM: Tracking and Mapping Recognizable Features

部署storageclass踩坑记录

Redis source code and design analysis -- 9. String object

Dynamic memory management

阿里云对象存储服务OSS前后联调

讲师征集令 | Apache DolphinScheduler Meetup分享嘉宾,期待你的议题和声音!

Redis源码与设计剖析 -- 7.快速列表

9、光线追踪
随机推荐
adb常用命令
Cadence(九)17.4规则与间距设置
C#的partial用法
单点登录-认证服务器与客户端的session过期时间如何统一
Three implementation methods of C # client program calling external program
Switch exchanges
Huck hurco industrial computer maintenance winmax CNC machine tool controller maintenance
Visual studio 2022 interesting and powerful intelligent auxiliary coding
【达人专栏】还不会用Apache Dolphinscheduler吗,大佬用时一个月写出的最全入门教学【二】
C language n battle -- linked list (IX)
赫克Hurco工控机维修WinMax数控机床控制器维修
Redis source code and design analysis -- 14. Database implementation
Xssgame games (XSS learning) level1-15
《天幕红尘》笔记与思考(四)相互价值无效
Redis源码与设计剖析 -- 8.对象系统
8、曲面几何
"The six programming languages I want most!"
Why can't we write really reusable C /f code?
6、重心坐标插值和图形渲染管线
村田muRata电源维修交换机服务器电源维修及主要功能特点