• 沒有找到結果。

4.5 人脸库资源管理

4.5.2 查询所有人脸库

}

响应示例

状态码:200 成功响应样例

{ "face_set_info": { "face_number": 0,

"face_set_id": "WYYOFIGb", "face_set_name": "test",

"create_date": "2018-05-28 02:19:00", "face_set_capacity": 10000,

"external_fields": { "timestamp" : { "type" : "long"

}, "id" : {

"type" : "string"

},

"number" : { "type" : "integer"

} } } }

状态码:400 失败响应样例

{ "error_code": "FRS.0002",

"error_msg": "The authentication token is abnormal."

}

状态码

状态码请参见状态码。

错误码

错误码请参见错误码。

4.5.2 查询所有人脸库

功能介绍

查询当前用户所有人脸库的状态信息。

前提条件:

请确保您已开通人脸识别服务,具体操作方法请参见申请服务。

调试

您可以在API Explorer中调试该接口。

URI

GET /v2/{project_id}/face-sets

4-48 路径参数

参数 是否必选 参数类型 描述

project_id 是 String 项目ID,获取方法请参见获取项

目ID/账号名/AK/SK。

请求参数

4-49 请求 Header 参数

参数 是否必选 参数类型 描述

X-Auth-Token 是 String 用户Token。

Token认证就是在调用API的时 候将Token加到请求消息头,从 而通过身份认证,获得操作API 的权限,响应消息头中X-Subject-Token的值即为Token。

响应参数

状态码:200

4-50 响应 Body 参数

参数 参数类型 描述

face_sets_info Array of

FaceSetInfo

objects

人脸库信息集合,详见FaceSetInfo。 调用失败 时无此字段。

4-51 FaceSetInfo

参数 参数类型 描述

face_number Integer 人脸库当中的人脸数量。

参数 参数类型 描述 external_field

s Object 用户的自定义字段。

face_set_id String 人脸库ID,随机生成的包含八个字符的字符串。

face_set_nam

e String 人脸库名称。

create_date String 创建时间。

face_set_capa

city Integer 人脸库最大的容量。

状态码: 400

4-52 响应 Body 参数

参数 参数类型 描述

error_code String 调用失败时的错误码,具体请参考错误码。 调用 成功时无此字段。

error_msg String 调用失败时的错误信息。 调用成功时无此字段。

请求示例

X-Auth-Token值获取方法请参见快速入门。

● 请求样例

GET https://{endpoint}/v2/{project_id}/face-sets Request Header:

Content-Type: application/json

X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDT...

● Python3语言请求代码示例(其他语言参照下列示例编写或使用FRS SDK)

# coding:utf-8 -*-import requests import base64

endpoint = '开通服务所在region的人脸识别服务域名' project_id = '开通服务所在region的用户项目ID' token = '用户获取得到的实际token值'

headers = {'Content-Type': 'application/json', 'X-Auth-Token': token}

url = "https://{endpoint}/v2/{project_id}/face-sets".format(endpoint=endpoint,project_id=project_id) response = requests.get(url, headers=headers, verify=False)

print(response.text)

● Java语言请求代码示例(其他语言参照下列示例编写或使用FRS SDK)

import com.huawei.trace.http.apache.httpclient.TraceApacheHttpClientBuilder;

import org.apache.http.HttpEntity;

import org.apache.http.HttpHeaders;

import org.apache.http.HttpResponse;

import org.apache.http.client.config.RequestConfig;

import org.apache.http.client.methods.HttpGet;

import org.apache.http.client.methods.HttpPost;

* 使用前需已配置HttpClient jar包。jar包可通过下载SDK获取 */

public class GetAllFaceSets {

protected static HttpClientBuilder buildClient(HttpClientBuilder httpClientBuilder) { SSLContext sslContext = null;

try {

sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {

public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { return true;

httpClientBuilder.setSSLContext(sslContext);

httpClientBuilder.setConnectionTimeToLive(30, TimeUnit.SECONDS);

HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE;

SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);

Registry<ConnectionSocketFactory> socketFactoryRegistry

= RegistryBuilder.<ConnectionSocketFactory>create().register("http",

PlainConnectionSocketFactory.getSocketFactory()).register("https", sslSocketFactory).build();

PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry);

connMgr.setMaxTotal(200);

connMgr.setDefaultMaxPerRoute(100);

httpClientBuilder.setConnectionManager(connMgr);

return httpClientBuilder;

}

public static String doGet(String url, String token, CloseableHttpClient client) { HttpGet get = new HttpGet(url);

get.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");

//time unit is milliseconds RequestConfig requestConfig =

RequestConfig.custom().setConnectTimeout(3000).setSocketTimeout(3000).build();

get.setConfig(requestConfig);

get.setHeader("X-Auth-Token", token);

HttpResponse response = null;

System.arraycopy(byteStream, 0, new byte[byteStream.length], 0, byteStream.length);

result = new String(byteStream, StandardCharsets.UTF_8);

public static void main(String[] args) {

CloseableHttpClient client = buildClient(TraceApacheHttpClientBuilder.create()).build();

// endpoint和project_id需要替换成实际信息。

String url = "https://{{endpoint}}/v2/{{project_id}}/face-sets";

String token = "对应region的token";

{ "face_sets_info": [ {

"face_number": 0,

"face_set_id": "ylXMMZTO", "face_set_name": "test",

"create_date": "2018-05-11 07:49:40", "face_set_capacity": 10000,

"external_fields": {

{ "error_code": "FRS.0002",

"error_msg": "The authentication token is abnormal."

}

状态码

状态码请参见状态码。

错误码

错误码请参见错误码。