Python使用百度api做人脸对比
2018-03-04 14:57
393 查看
安装SDK:
pip install baidu-aip如果在pycharm里也可以在setting----Project Interpreter---右边绿色加号,输入baidu,安装baidu-aip
入门代码:
先去百度AI开放平台注册一个账号,然后开通人脸识别,免费的http://ai.baidu.com/tech/face之后把得到的Api key secretkey 填进去。from aip import AipFace """ 你的 APPID AK SK """ APP_ID = '你的 App ID' API_KEY = '你的 Api Key' SECRET_KEY = '你的 Secret Key' client = AipFace(APP_ID, API_KEY, SECRET_KEY) """ 读取图片 """ def get_file_content(filePath): with open(filePath, 'rb') as fp: return fp.read() images = [ get_file_content('example0.jpg'), get_file_content('example1.jpg'), ] """ 调用人脸比对 """ result_json=client.match(images); print(result_json)会自动把你当前工程目录下的example0.jpg 和example1.jpg进行比对。
最后会得到这样一个json字符串{'result': [{'index_i': '0', 'index_j': '1', 'score': 21.207210540771}], 'result_num': 1, 'log_id': 2864712345030414}里面的score就是两张人脸的相似度 了,这里我用的不同的人脸,只有21%左右
可以再写一个判断的方法:def judge(images):
result_json = client.match(images);
result = result_json['result'][0]['score']
if result > 80:
print("同一個人")
else:
print("不是同一個人")
相关文章推荐
- python3.6+百度人脸识别API进行照片人脸对比
- Python3使用微软人脸API-1.2创建人员组人员训练识别
- 百度人脸识别API 的使用
- 【百度地图API】百度API卫星图使用方法和卫星图对比工具
- 【百度地图API】百度API卫星图使用方法和卫星图对比工具
- 【百度地图API】百度API卫星图使用方法和卫星图对比工具
- Python使用百度API上传文件到百度网盘代码分享
- 【百度地图API】百度API卫星图使用方法和卫星图对比工具
- 使用python及百度API对百度poi数据进行爬取(一)
- python,使用百度api实现复制截图中的文字
- 获取经纬度api使用心得【对比百度,谷歌地图API】
- 百度API卫星图使用方法和卫星图对比工具
- 突然发现百度的API越来越好用了,简单使用百度API精准定位IP地址。附Python代码
- 使用python及百度API对百度poi数据进行爬取(二)
- 使用python及百度API对百度poi数据进行爬取(三)
- Python3使用微软人脸API-1.1人脸检测
- 百度云 人脸对比API 使用(nodejs)
- 使用Python结合Face++ API识别人脸
- 百度API之人脸检测-Python
- Python使用百度API上传文件到百度网盘代码分享