嘴唇识别
主要是采用百度 AI 开放平台的人脸识别,它可以识别人脸的 150 个关键点,其中嘴巴的关键点就有 48 个
熟悉百度 AI 开放平台的小伙伴都知道,需要使用百度控制台的 AK 和 SK 才能生成 access_token 变量
ak = ‘xxx’
sk = ‘xxx’
host = ‘https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=’ + ak + ‘&client_secret=’ + sk
response = requests.get(host)
if response:
access_token = response.json()[‘access_token’]
else:
raise Exception(‘access_token 获取失败’)
获取 access_token 后,在网上找一个美女头像图片作为底片,转换成 base64 位格式当做参数请求得到人脸的 150 个关键点
图片转 base64
pic_path = ‘/Users/xx/Desktop/kh/原图.png’
with open (pic_path, ‘rb’) as f:
base64_data = base64.b64encode(f.read())
image:图片,image_type:图片格式,face_field:请求的结果,landmark150为人脸的 150 个关键点
params = ‘{“image”:"’+base64_data.decode(‘utf-8’)+‘",“image_type”:“BASE64”,“face_field”:“landmark150”}’
request_url = ‘https://aip.baidubce.com/rest/2.0/face/v3/detect?access_token=’ + access_token
headers = {‘content-type’: ‘application/json’}
response = requests.post(request_url, data=params, headers=headers)
if response:
face = response.json()
else:
raise Exception(‘人脸关键点获取失败’)
示例结果
取到人脸关键点后,参照人脸识别的文档(下图)可以得到嘴唇的 48 个关键点
上嘴唇关键点,按顺时针方向的顺序组成一个多边形
mouth_lip_upper_point_list = [
‘mouth_corner_right_outer’,‘mouth_lip_upper_outer_1’,‘mouth_lip_upper_outer_2’,‘mouth_lip_upper_outer_3’,
‘mouth_lip_upper_outer_4’,‘mouth_lip_upper_outer_5’,‘mouth_lip_upper_outer_6’,‘mouth_lip_upper_outer_7’,
‘mouth_lip_upper_outer_8’,‘mouth_lip_upper_outer_9’,‘mouth_lip_upper_outer_10’,‘mouth_lip_upper_outer_11’,
‘mouth_corner_left_outer’,‘mouth_corner_left_inner’,‘mouth_lip_upper_inner_11’,‘mouth_lip_upper_inner_10’,
‘mouth_lip_upper_inner_9’,‘mouth_lip_upper_inner_8’,‘mouth_lip_upper_inner_7’,‘mouth_lip_upper_inner_6’,
‘mouth_lip_upper_inner_5’,‘mouth_lip_upper_inner_4’,‘mouth_lip_upper_inner_3’,‘mouth_lip_upper_inner_2’,
‘mouth_lip_upper_inner_1’,‘mouth_corner_right_inner’,‘mouth_corner_right_outer’
]
下嘴唇关键点,按顺时针方向的顺序组成一个多边形
mouth_lip_low_point_list = [
‘mouth_corner_right_outer’,‘mouth_corner_right_inner’,‘mouth_lip_lower_inner_1’,‘mouth_lip_lower_inner_2’,
‘mouth_lip_lower_inner_3’,‘mouth_lip_lower_inner_4’,‘mouth_lip_lower_inner_5’,‘mouth_lip_lower_inner_6’,
‘mouth_lip_lower_inner_7’,‘mouth_lip_lower_inner_8’,‘mouth_lip_lower_inner_9’,‘mouth_lip_lower_inner_10’,
‘mouth_lip_lower_inner_11’,‘mouth_corner_left_outer’,‘mouth_lip_lower_outer_11’,‘mouth_lip_lower_outer_10’,
‘mouth_lip_lower_outer_9’,‘mouth_lip_lower_outer_8’,‘mouth_lip_lower_outer_7’,‘mouth_lip_lower_outer_6’,
‘mouth_lip_lower_outer_5’,‘mouth_lip_lower_outer_4’,‘mouth_lip_lower_outer_3’,‘mouth_lip_lower_outer_2’,
‘mouth_lip_lower_outer_1’,‘mouth_corner_right_outer’
]
for f in face[‘result’][‘face_list’]:
上嘴唇关键点 [(x,y),(x,y),(x,y)] 元组列表
mouth_lip_upper_list = []
下嘴唇关键点 [(x,y),(x,y),(x,y)] 元组列表
mouth_lip_low_list = []
for point in mouth_lip_upper_point_list:
p = f[‘landmark150’][point]
mouth_lip_upper_list.append((p[‘x’], p[‘y’]))
学好 Python 不论是就业还是做副业赚钱都不错,但要学会 Python 还是要有一个学习规划。最后大家分享一份全套的 Python 学习资料,给那些想学习 Python 的小伙伴们一点帮助!
一、Python所有方向的学习路线
Python所有方向路线就是把Python常用的技术点做整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。
二、学习软件
工欲善其事必先利其器。学习Python常用的开发软件都在这里了,给大家节省了很多时间。
三、全套PDF电子书
书籍的好处就在于权威和体系健全,刚开始学习的时候你可以只看视频或者听某个人讲课,但等你学完之后,你觉得你掌握了,这时候建议还是得去看一下书籍,看权威技术书籍也是每个程序员必经之路。
四、入门学习视频
我们在看视频学习的时候,不能光动眼动脑不动手,比较科学的学习方法是在理解之后运用它们,这时候练手项目就很适合了。
五、实战案例
光学理论是没用的,要学会跟着一起敲,要动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。
六、面试资料
我们学习Python必然是为了找到高薪的工作,下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料,并且有阿里大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!