调用API实现识别
在baidu_api目录下新建baidu_api_face目录,将下载的人脸识别的SDK解压到该目录下,在baidu_api_face目录下新建face_predict.py文件。
from aip import AipFace
import base64
""" 你的 APPID AK SK """
APP_ID = '你的 App ID'
API_KEY = '你的 Api Key'
SECRET_KEY = '你的 Secret Key'
client = AipFace(APP_ID, API_KEY, SECRET_KEY)
""" 选择BASE64 """
filePath ="pic.png"
with open(filePath,"rb") as f:
b64encode是编码
base64_data = base64.b64encode(f.read())
image = str(base64_data,'utf-8')
imageType = "BASE64"
groupIdList = "group"
""" 调用人脸搜索 """
print (client.search(image, imageType, groupIdList))
在groupIdList中可输入人脸库的用户组ID,client.search()函数可调用人脸识别。