习惯性的 有代码先上代码:
from aip import AipFace #需要安装baidu-aip环境
import base64
APP_ID=input("请输入您的app id:")
API_KEY=input("请输入您的api key:")
SECRET_KEY=input("请输入您的aecret key:")
groupIdList=input("请输入所要检索的用户组(可多选用,隔开):")
print ("初始化完成")
imageType = "BASE64"
filePath=input("输入本地图片地址:")#就是照片文件位置(不支持gif)
client = AipFace(APP_ID, API_KEY, SECRET_KEY)
f=open(filePath,"rb")
data = base64.b64encode(f.read())
f.close()
image=str(data,'UTF-8')
result = client.search(image, imageType, groupIdList);
print(result["result"]["user_list"][0]["group_id"]) #用户组名称
print(result["result"]["user_list"][0]["user_id"]) #用户ID
print(result["result"]["user_list"][0]["score"]) #相似度
if result["error_msg"] in "SUCCESS":
score=result["result"]["user_list"][0]["score"]
user_id=result["result"]["user_list"][0]["user_id"]
if score>85:
print(user_id,":识别成功")
else:
print("人脸库无此人")
else:
print("error:",result["error_msg"])
此程序依照百度SDK文档开发。目前只支持1:N识别(一张人脸对比库中的多张人脸)。以后更新M:N识别
用户可以自己注册一个百度AI平台账号,新建一个人脸识别应用,获取APP ID、AK(API Key)和SK(Secret Key)。在创建的应用下建立人脸库。
然后可以在人脸库中上传照片和分组。
#使用方法
根据程序提示分别填入APP ID、AK(API Key)和SK(Secret Key),最后输入本地的照片地址。
最后获得结果
未经允许,严谨转载
附上博客链接