用Python识别人脸,人种等各种信息
作者:Jeru_d39e 时间:2023-12-22 08:22:17
最近几天了解了一下人脸识别,应用场景可以是图片标注,商品图和广告图中有没有模特,有几个模特,模特的性别,年龄,颜值,表情等数据的挖掘。
基础的识别用dlib来实现,dlib是一个机器学习的包,主要用C++写的,但是也有Python版本。其中最流行的一个功能是Facial Landmark Detection, 配备已经训练好的轮廓预测模型,叫shape_predictor_68_face_landmarks.dat, 从名字就可以看出,它可以检测出面部的68个关键点,包括五官和外轮廓等。
安装dlib会花比较长时间,因为依赖包有十个左右,装完了dlib别忘了下载predictor数据文件。
wget
http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2
pip install dlib
我在Adrian大神的代码做了一点修改和封装,先定位脸部的方框,box_face画出方框,在此基础上可选调用tag_face_number来标注脸的标号或者draw_face_landmarks来标注特征点,也可以直接调用count_faces来统计脸的个数,mark_all_faces给所有的脸把所有信息都加上。
拿九张模特图来试试,半脸的不行,侧的太厉害不行,其它都能识别出来。
一张图多张脸的也毫无压力
接下来性别和年龄就不好做了,必须通过机器训练数据,还没时间摸透,又想尽快拿到这些标注,于是先走捷径去调face++的API, 注册个账号申请key和secret即可,免费账户有qps限制,且一张照片内最多支持五人识别。
官方的代码示例极差,而且还是只支持Python2的, 收先要改写一下。Attribute中有很多数据可以拿,你想的到的想不到的都有,甚至包括颜值,人种等。颜值还算靠谱,范冰冰90分,凤姐49分,人种就难说了,欧美模特分分钟当成Asian.
机器说: 性别女,表情偏悲伤,颜值89分,28岁,亚洲人,基本没笑
{'image_id': 'wPGIyROqltTdjvRX3zopbg==', 'request_id': '1519574701,3113e37e-b000-4440-af08-871831cf1ba8', 'time_used': 355, 'faces': [{'attributes': {'emotion': {'sadness': 93.448, 'neutral': 4.114, 'disgust': 0.002, 'anger': 0.002, 'surprise': 2.414, 'fear': 0.002, 'happiness': 0.018}, 'beauty': {'female_score': 89.348, 'male_score': 88.925}, 'gender': {'value': 'Female'}, 'age': {'value': 28}, 'headpose': {'yaw_angle': 17.526142, 'pitch_angle': 11.047059, 'roll_angle': 19.623343}, 'smile': {'threshold': 30.1, 'value': 28.532}, 'ethnicity': {'value': 'Asian'}}, 'face_rectangle': {'width': 202, 'top': 103, 'left': 69, 'height': 202}, 'face_token': '7be6a72f497ed16cc7883424584052c5'}]}
机器说: 性别男,表情很快乐,颜值52分,61岁,黑人,大笑
{'image_id': 'YZ5wzeVDiAgCN9yIFX44Gw==', 'request_id': '1519574926,31f6d4d8-bdf6-4863-b29a-cf61ff04ffbe', 'time_used': 323, 'faces': [{'attributes': {'emotion': {'sadness': 0.0, 'neutral': 0.0, 'disgust': 0.0, 'anger': 0.0, 'surprise': 0.0, 'fear': 0.0, 'happiness': 99.999}, 'beauty': {'female_score': 62.678, 'male_score': 51.847}, 'gender': {'value': 'Male'}, 'age': {'value': 61}, 'headpose': {'yaw_angle': 2.6326802, 'pitch_angle': 11.909821, 'roll_angle': -11.707241}, 'smile': {'threshold': 30.1, 'value': 99.081}, 'ethnicity': {'value': 'Black'}}, 'face_rectangle': {'width': 208, 'top': 88, 'left': 120, 'height': 208}, 'face_token': '19067cf0f5358312c109a0e70bab62ae'}]}
来源:https://www.jianshu.com/p/d6507c5f99b0
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
NumPy中的维度Axis详解
![](https://img.aspxhome.com/file/2023/7/82737_0s.jpg)
Python3 执行Linux Bash命令的方法
python神经网络Pytorch中Tensorboard函数使用
![](https://img.aspxhome.com/file/2023/3/78583_0s.png)
一文读懂Python版本管理工具Pyenv使用
![](https://img.aspxhome.com/file/2023/0/77760_0s.png)
如何在Python中进行异常处理
python爬虫模拟登录之图片验证码实现详解
![](https://img.aspxhome.com/file/2023/9/130679_0s.png)
Python实现的三层BP神经网络算法示例
![](https://img.aspxhome.com/file/2023/0/98320_0s.png)
Ubuntu安装Jupyter Notebook教程
![](https://img.aspxhome.com/file/2023/5/77845_0s.png)
python点云地面点滤波(Progressive Morphological Filter)算法介绍(PCL库)
![](https://img.aspxhome.com/file/2023/9/96919_0s.png)
Python爬虫之m3u8文件里提取小视频的正确姿势
![](https://img.aspxhome.com/file/2023/0/103180_0s.png)
Python基于Webhook实现github自动化部署
![](https://img.aspxhome.com/file/2023/2/77752_0s.jpg)
python 计算数组中每个数字出现多少次--“Bucket”桶的思想
![](https://img.aspxhome.com/file/2023/7/68947_0s.png)
JSP 开发之 releaseSession的实例详解
最常用的12种设计模式小结
MySQL慢查询日志的配置与使用教程
![](https://img.aspxhome.com/file/2023/8/115558_0s.png)
vue实现添加标签demo示例代码
![](https://img.aspxhome.com/file/2023/9/125299_0s.png)
python 正则式 概述及常用字符
如何使用conda和pip批量安装Python包
![](https://img.aspxhome.com/file/2023/8/127298_0s.png)
python在不同条件下的输入与输出
Go语言中rune方法使用详解
![](https://img.aspxhome.com/file/2023/0/134400_0s.png)