CDN加速

文档中心 API文档 AI服务 人脸定位接口

人脸定位接口

更新时间:2019-12-12 17:32:20

适用产品:定制化接口

接口描述

根据用户上传的图片,识别出图片里的所有人脸位置。

请求参数

-
参数名称类型必填描述
filestring用户传上来的识别图片。采用base64加密为字符串

返回参数

-
参数名称类型描述
codestring返回调用结果的状态
messagestring调用接口,返回状态码的说明
datalist返回的为识别到的人脸图片坐标和准确率。list里为准确率和左上角坐标及右下角坐标。

错误码

错误代码(code)描述(message)HTTP状态码语义
30052002post字段没有图片内容200

示例

PYTHON调用示例
示例说明
请求示例
复制
#!/usr/bin/env python
# -- coding: utf-8 --


import requests
import sys
import os
import json
import base64
import time
from hashlib import sha256

url = 'http://open.chinanetcenter.com/wsface/v1/face/detect'

username = 'xxx'
apikey = 'xxx'
__curPath__ = os.path.split(os.path.realpath(__file__))[0]


def getDate():
    import datetime
    GMT_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'
    date_gmt = datetime.datetime.utcnow().strftime(GMT_FORMAT)
    print("getDate: " + date_gmt)
    return date_gmt


def sha(date):
    import hmac
    print("sha: " + date)
    signed_apikey = hmac.new(apikey.encode(
        'utf-8'), date.encode('utf-8'), sha256).digest()
    signed_apikey = base64.b64encode(signed_apikey)
    print("sha: " + signed_apikey.decode())
    return signed_apikey


def encode(time):
    print("encode: " + time.decode())
    msg = username + ":" + time.decode()
    result = base64.b64encode(msg.encode('utf-8'))
    print("encode: " + result.decode())
    return result


def getAuth():
    return encode(sha(getDate()))


def getABase64StrFromFile(fname):
    with open(fname, 'rb') as f:
        c = f.read()
        c = base64.b64encode(c)
        return str(c, encoding='utf-8')


def connect(fname='./Images/00002.jpg'):
    auth = getAuth()
    auth = 'Basic ' + auth.decode()
    d = {"file": getABase64StrFromFile(fname)}
    headers = {'Content-Type': 'application/json', 'Accept': "application/json",
               "Date": getDate(), 'Authorization': auth}
    print(url)
    r = requests.post(url, headers=headers, data=json.dumps(d))
    ret = r.text
    print(ret)


if __name__ == '__main__':
    connect()
返回示例
复制
{"code": "0", "message": "ok", "data": [[0.9993607997894287, [109.02743530273438, 705.407470703125, 221.68093872070312, 793.938232421875]], [0.9911298751831055, [144.29440307617188, 622.3575439453125, 231.91624450683594, 687.8494873046875]], [0.9893971681594849, [162.9700469970703, 525.968505859375, 240.36660766601562, 587.4498291015625]], [0.952801525592804, [170.21066284179688, 973.635498046875, 266.326171875, 1016.667236328125]], [0.921448290348053, [189.88677978515625, 845.3375244140625, 260.0375671386719, 903.3360595703125]], [0.8472548723220825, [183.10133361816406, 461.7531433105469, 248.4606170654297, 506.4600524902344]], [0.5468629598617554, [201.60169982910156, 361.8038330078125, 256.8813781738281, 401.504638671875]]]}