python 使用百度AI接口进行人脸对比的步骤
作者:可爱的黑精灵 时间:2021-07-06 02:20:06
目录
1. 注册百度云账号
2. 安 * aidu python api
3.调用摄像头
4.完整测试程序
1. 注册百度云账号
注册百度智能云,提交申请。
创建应用获取AppID,API Key,Secret Key。
2. 安 * aidu python api
人脸对比 API 文档
pip install baidu-aip
调用:
import base64
from aip import AipFace
APP_ID = '你的 App ID'
API_KEY = '你的 Api Key'
SECRET_KEY = '你的 Secret Key'
client = AipFace(APP_ID, API_KEY, SECRET_KEY)
result = client.match([
{
'image': str(base64.b64encode(open('D:/chenjy/1.png', 'rb').read()), 'utf-8'),
'image_type': 'BASE64',
},
{
'image': str(base64.b64encode(open('D:/chenjy/2.png', 'rb').read()), 'utf-8'),
'image_type': 'BASE64',
}
])
print(result)
返回值:
返回主要参数说明:
参数名 | 必选 | 类型 | 说明 |
---|---|---|---|
score | 是 | float | 人脸相似度得分,推荐阈值80分 |
face_list | 是 | array | 人脸信息列表 |
face_token | 是 | string | 人脸的唯一标志 |
3.调用摄像头
import cv2
cap = cv2.VideoCapture(0) # 打开摄像头
while True:
ret, frame = cap.read()
frame = cv2.flip(frame, 1)
cv2.imshow('window', frame)
cv2.imwrite('D:/chenjy/2.png', frame) # 保存路径
cv2.waitKey(2000)
cap.release()
cv2.destroyAllWindows()
4.完整测试程序
import cv2
import base64
from aip import AipFace
APP_ID = '你的 App ID'
API_KEY = '你的 Api Key'
SECRET_KEY = '你的 Secret Key'
client = AipFace(APP_ID, API_KEY, SECRET_KEY)
def get_result():
result = client.match([
{
'image': str(base64.b64encode(open('D:/chenjy/1.png', 'rb').read()), 'utf-8'),
'image_type': 'BASE64',
},
{
'image': str(base64.b64encode(open('D:/chenjy/2.png', 'rb').read()), 'utf-8'),
'image_type': 'BASE64',
}
])
if result['error_msg'] == 'SUCCESS':
score = result['result']['score']
print(result)
print('相似度:'+str(score))
else:
print('服务器错误')
cap = cv2.VideoCapture(0) # 打开摄像头
while True:
ret, frame = cap.read()
frame = cv2.flip(frame, 1)
cv2.imshow('window', frame)
cv2.imwrite('D:/chenjy/2.png', frame) # 保存路径
cv2.waitKey(2000)
get_result()
cap.release()
cv2.destroyAllWindows()
结果:
照片加了模糊处理
来源:https://www.cnblogs.com/chenjy1225/p/14371078.html
标签:python,百度ai,人脸对比
0
投稿
猜你喜欢
深入分析C#连接Oracle数据库的连接字符串详解
2024-01-20 23:46:29
Django如何实现内容缓存示例详解
2022-02-23 15:33:01
python的pstuil模块使用方法总结
2022-10-09 22:47:16
Python中使用第三方库xlrd来写入Excel文件示例
2023-08-16 21:37:29
go语言实现聊天服务器的示例代码
2024-04-26 17:17:39
Android通过PHP服务器实现登录功能
2023-07-02 07:08:58
Python办公自动化PPT批量转换操作
2023-11-07 16:54:20
JS实现淘宝支付宝网站的控制台菜单效果
2023-07-22 22:26:12
盗亦有道 Web2.0网站优秀模仿者逐个数
2007-09-11 19:46:00
pytorch .detach() .detach_() 和 .data用于切断反向传播的实现
2022-01-30 21:24:56
如何使用python传入不确定个数参数
2023-10-27 22:56:36
Django 内置权限扩展案例详解
2022-08-21 23:25:45
javascript实现编写网页版计算器
2024-04-23 09:26:25
Python 使用list和tuple+条件判断详解
2022-05-13 16:36:39
Python中time库的使用(日期时间)
2022-11-12 09:04:23
oracle sqlplus 常用命令大全
2009-05-24 19:47:00
Python解析JSON数据的基本方法实例代码
2021-02-13 20:40:01
js模拟抽奖代码
2008-07-20 12:38:00
Python如何读取、写入CSV数据
2022-02-17 14:03:31
XML轻松学习手册(3)XML的术语
2008-09-05 17:17:00