首页 技术 正文
技术 2022年11月9日
0 收藏 302 点赞 4,926 浏览 2249 个字

用python来做人脸识别代码量少 思路清晰,

在使用之前我们需要在我们的配置的编译器中通过pip       install baidu-aip  即可

from aip import AipFace

就可以开始使用api了 我们第一次接触这个东西不妨

help(AipFace)

你就可以看到他所支持的功能。

在使用之前我们需要在百度的后台创建应用。将我们人脸都存放入库中。

其次我们要了解一个概念,我们要将本机中的图片与后台的人脸对比的话我们需要将图片转成base64的字符串的格式

import base64
f = open('./photo/mr.jpg', 'rb')
image = base64.b64encode(f.read())
image64 = str(image,'utf-8')
image_type = "BASE64"

当然我们也可以将base64码转换成图片。

人脸检测的原理是通过机器学习转化提前图片人脸中的七十二个关键点。并进行其他的分析。

python3的代码为

'''
# 人脸检测与属性分析
'''request_url = "https://img.zhankr.net/ndsinsce1ve60916.jpg', 'rb')
image = base64.b64encode(f.read())
image64 = str(image,'utf-8')
image_type = "BASE64"# params = "{\"image\":\"%s\",\"image_type\":\"BASE64\",\"face_field\":\"faceshape,facetype\"}"%image64
params = {'image': image64,'image_type':"BASE64",'face_field': 'faceshape,facetype'}
# 此处的faceshape和facetype需要自己加上去 更具自己需要的返回值params = urllib.parse.urlencode(params).encode("utf-8")access_token = '[24.3941b86dfcbc8eaea432d11df4f6660d.2592000.1542368987.282335-14255146]'
request_url = request_url + "?access_token=" + access_tokenrequest = urllib.request.urlopen(url=request_url, data=params) # 发送请求content = request.read() # 将返回结果读取出来
print(content) # 显示返回结果import urllib.request,sys,base64
import urllib.parse# 返回实例
a = {'error_code': 0,
'error_msg': 'SUCCESS',
'log_id': 1011018945051,
'timestamp': 1540301526,
'cached': 0,
'result': {'face_num': 1,
'face_list': [{'face_token': '80ed04e5e8771730b3fe240f8ead4e97',
'location': {'left': 564.6082764,
'top': 117.9681244,
'width': 263,
'height': 265,
'rotation': 1},
'face_probability': 1,
'angle': {'yaw': -0.301689893,
'pitch': -15.59528351,
'roll': 0.9747127891
}
}
]
}
}

具体各种属性请看百度文档  https://img.zhankr.net/qbutjtfsor260917′, ‘rb’)
image = base64.b64encode(f.read())
image64 = str(image,’utf-8′)
image_type = “BASE64”
print(client.detect(image64, image_type)) # 此处的返回值为人脸的基本检测的数值效果# print(strs)
# 人脸检测
# image = str(strs) # 取决于image_type参数,传入BASE64字符串或URL字符串或FACE_TOKEN字符串imageType = “BASE64″groupIdList = “17ai_1″””” 调用人脸搜索 “””print(client.search(str(image64), image_type, groupIdList))# 将返回对比结果”’
“”” 如果有可选参数 “””
options = {}
options[“quality_control”] = “NORMAL”
options[“liveness_control”] = “LOW”
options[“user_id”] = “233451”
options[“max_user_num”] = 3″”” 带参数调用人脸搜索 “””
# print(client.search(image, imageType, , options))# 人脸搜索返回例子
”’
face = {
“face_token”: “fid”,
“user_list”: [
{
“group_id”: “test1”,
“user_id”: “u333333”,
“user_info”: “Test User”,
“score”: 99.3
}
]
}

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,488
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,489
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,290