#!/usr/bin/python3
import tornado.web
from tornado.escape import json_decode
import json
from aip import AipFace
import time
import requests
import json
class faceseach(tornado.web.RequestHandler):
def post(self,*args,**kwargs):
data=json_decode(self.request.body)
""" 你的 APPID AK SK """
APP_ID = '17328499'
API_KEY = 'mZY1ktlANqz8Pq7TX3g7vQCx'
SECRET_KEY = 'djgSb8bTWuAF4ZXT3x8tqxlO09mXGNrc'
client = AipFace(APP_ID, API_KEY, SECRET_KEY)
imageType="URL"
groupIdList = "test1"
""" 调用人脸搜索 """
#result1 = client.search(data["url"], imageType, groupIdList)
""" 如果有可选参数 """
options = {}
options["max_face_num"] = 10
options["match_threshold"] = 90
options["quality_control"] = "NONE"
options["liveness_control"] = "LOW"
#options["user_id"] = data["user"]
options["max_user_num"] = 10
""" 带参数调用人脸搜索只识别一张人脸 """
#result1=client.search(data["url"], imageType, groupIdList, options)
""" 带参数调用人脸搜索 M:N 识别 """
result1=client.multiSearch(data["url"], imageType, groupIdList, options)
print(result1)
if result1["error_code"]==0:
self.finish(json.dumps({"error_code":0,"error_info":"搜索成功","data":{"user_id": result1["result"]["user_list"][0]["user_id"],"user_info": result1["result"]["user_list"][0]["user_info"]}},ensure_ascii=False))
else:
self.finish(json.dumps({"error_code": 1, "error_info": "未找到图片人脸",},ensure_ascii=False))
返回:
{'error_code': 0, 'error_msg': 'SUCCESS', 'log_id': 747956995557560421, 'timestamp': 1569555756, 'cached': 0, 'result': {'face_num
': 5, 'face_list': [{'face_token': 'ed2cc834efef97e29117d1e15cba6917', 'location': {'left': 332.65, 'top': 27.86, 'width': 44, 'he
ight': 40, 'rotation': 0}, 'user_list': [{'group_id': 'test1', 'user_id': 'james', 'user_info': 'james', 'score': 95.572891235352}
, {'group_id': 'test1', 'user_id': 'test1_zhanmusi', 'user_info': '', 'score': 95.572891235352}, {'group_id': 'test1', 'user_id':
'paul', 'user_info': '', 'score': 95.001075744629}]}, {'face_token': 'ab26a5507f1c5e70346e21f110f65e50', 'location': {'left': 224.
97, 'top': 57.54, 'width': 41, 'height': 40, 'rotation': 1}, 'user_list': [{'group_id': 'test1', 'user_id': 'paul', 'user_info': '
', 'score': 92.716430664062}]}, {'face_token': 'f2914074434b89a982b372d0f9cc0411', 'location': {'left': 485.97, 'top': 218.18, 'wi
dth': 37, 'height': 35, 'rotation': -3}, 'user_list': []}, {'face_token': '0234f97d2aa4ba5276e955278a117eda', 'location': {'left':
440.92, 'top': 214.23, 'width': 36, 'height': 31, 'rotation': -1}, 'user_list': []}, {'face_token': 'f320dc30002178336b51b1a0d3ed
e9bb', 'location': {'left': 471.95, 'top': 72.19, 'width': 33, 'height': 29, 'rotation': -2}, 'user_list': []}]}}
人脸注册:
组:test1
用户:harden,注册图片"https://ss.xiaoqiu.tv//faceharden2.jpg"
用户:james,注册图片"https://ss.xiaoqiu.tv//face9.jpg"
用户:wade,注册图片"https://ss.xiaoqiu.tv//facewade1.jpg"
用户:paul,注册图片""https://ss.xiaoqiu.tv//facepaul4.jpg"
搜索图片:"url":"https://ss.xiaoqiu.tv//facejamesouvin.jpg"
一般阈值设多大合适?我设70%
看着好复杂啊
有阈值控制的。你可以根据这个来决策。谁家的接口也不太可能保证100%的识别准确。