状态码
状态码请参见状态码。
错误码
错误码请参见错误码。
7.5 人脸库资源管理(V1)
7.5.1 创建人脸库
功能介绍
创建用于存储人脸特征的人脸库。您最多可以创建10个人脸库,每个人脸库最大容量 为10万个人脸特征。如有更大规格的需求请联系客服。V1版本接口已经停售,该接口 仅老用户可用,新用户推荐使用V2版本API。
前提条件:
请确保您已开通人脸识别服务,具体操作方法请参见申请服务。
说明
application/json请求的body中,请使用标准Json格式。
URI
POST /v1/{project_id}/face-sets
表7-17 路径参数
参数 是否必选 参数类型 描述
project_id 是 String 项目ID,获取方法请参见获取项
目ID/账号名/AK/SK。
请求参数
表7-18 请求 Header 参数
参数 是否必选 参数类型 描述
X-Auth-Token 是 String 用户Token。
Token认证就是在调用API的时 候将Token加到请求消息头,从 而通过身份认证,获得操作API 的权限,响应消息头中X-Subject-Token的值即为Token。
表7-19 请求 Body 参数
参数名 参数类型 是否必选 说明
face_set_name String 是 人脸库的名称。
建议人脸库的名称不要以下划 线“_”开头,否则云监控服务 会无法采集人脸数量。
face_set_capacity Integer 否 人脸库最大的容量,填写1万 整数倍的数字,例如:
30000。
默认为100000,最大值为 100000,可通过创建新的人脸 库进行扩容,每个用户可免费 使用10个人脸库,每个人脸库 容量为10万个人脸特征。如需 扩容单个人脸库规模,请联系 华为云客服确认扩容规模与价 格。
参数名 参数类型 是否必选 说明
external_fields Json 否 用户自定义数据,自定义字段 不能以vector、
bounding_box、
external_image_id、face_id、
create_time、_id、_all、
_source等字段命名,这些字段 为内置字段,自定义字段避免 使用。
Json字符串不校验重复性,自 定义字段的key值长度范围为 [1,36],string类型的value长 度范围为[1,256],具体参见自
定义字段。
如果在后续操作中,使用该自 定义字段向人脸库中添加人 脸,需要在创建人脸库时定义 该字段。
响应参数
状态码:200
表7-20 响应 Body 参数
参数名 参数类型 说明
face_set_info Object 人脸库信息,详见FaceSetInfo。
调用失败时无此字段。
error_code String 调用失败时的错误码,具体请参考错
误码。
调用成功时无此字段。
error_msg String 调用失败时的错误信息。
调用成功时无此字段。
请求示例
● 请求样例
POST https://{endpoint}/v1/{project_id}/face-sets Request Header:
Content-Type: application/json
X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDT...
Request Body:
{ "face_set_name": "test", "face_set_capacity": 100000, "external_fields" : { "timestamp" : {
"type" : "long"
● 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}/v1/{project_id}/face-sets".format(endpoint=endpoint,project_id=project_id) body = {
"face_set_name": "test", "face_set_capacity": 100000, "external_fields" : { "timestamp" : {
response = requests.post(url, headers=headers, json=body, verify=False) print(response.text)
● Java语言请求代码示例(其他语言参照下列示例编写或使用FRS SDK)
import com.huawei.trace.http.apache.httpclient.TraceApacheHttpClientBuilder;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
/** * 此demo仅供测试使用,强烈建议使用SDK
* 使用前需已配置HttpClient jar包。jar包可通过下载SDK获取 */
public class CreateFaceSet {
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 doPost(String url, String jsonStr, String token, CloseableHttpClient client) { HttpPost post = new HttpPost(url);
StringEntity entity = new StringEntity(jsonStr, ContentType.APPLICATION_JSON);
post.setEntity(entity);
post.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
//time unit is milliseconds RequestConfig requestConfig =
RequestConfig.custom().setConnectTimeout(3000).setSocketTimeout(3000).build();
post.setConfig(requestConfig);
post.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}}/v1/{{project_id}}/face-sets";
String jsonStr = "{ \"face_set_name\": \"test\", \"face_set_capacity\": 100000, \"external_fields\" : { \"timestamp\" : { \"type\" : \"long\" }, \"id\" : { \"type\" : \"string\" }, \"number\" : { \"type\" :
\"integer\" }}}";
String token = "对应region的token";
String result = doPost(url, jsonStr, token, client);
System.out.println(result);
} }
响应示例
状态码: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."
}
状态码
状态码请参见状态码。
错误码
错误码请参见错误码。
7.5.2 查询所有人脸库
功能介绍
查询当前用户所有人脸库的状态信息。V1版本接口已经停售,该接口仅老用户可用,
新用户推荐使用V2版本API。
前提条件:
请确保您已开通人脸识别服务,具体操作方法请参见申请服务。
URI
GET /v1/{project_id}/face-sets
表7-21 路径参数
参数 是否必选 参数类型 描述
project_id 是 String 项目ID,获取方法请参见获取项
目ID/账号名/AK/SK。
请求参数
表7-22 请求 Header 参数
参数 是否必选 参数类型 描述
X-Auth-Token 是 String 用户Token。
Token认证就是在调用API的时 候将Token加到请求消息头,从 而通过身份认证,获得操作API 的权限,响应消息头中X-Subject-Token的值即为Token。
响应参数
状态码:200
表7-23 响应 Body 参数
参数名 参数类型 说明
face_sets_info List 人脸库信息集合,详见
FaceSetInfo。
调用失败时无此字段。
error_code String 调用失败时的错误码,具
体请参考错误码。
调用成功时无此字段。
error_msg String 调用失败时的错误信息。
调用成功时无此字段。
请求示例
● 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}/v1/{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;
* 使用前需已配置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;
} }).build();
} catch (NoSuchAlgorithmException e) {
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}}/v1/{{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": { "number": { "type": "integer"
}, "id": {
"type": "string"
},
"timestamp": { "type": "long"
} } } ] }
状态码:400 失败响应样例
{ "error_code": "FRS.0002",
"error_msg": "The authentication token is abnormal."
}
状态码
状态码请参见状态码。
错误码
错误码请参见错误码。
7.5.3 查询人脸库
功能介绍
查询人脸库当前的状态。V1版本接口已经停售,该接口仅老用户可用,新用户推荐使 用V2版本API。
前提条件:
请确保您已开通人脸识别服务,具体操作方法请参见申请服务。
URI
GET /v1/{project_id}/face-sets/{face_set_name}
表7-24 路径参数
参数 是否必选 参数类型 描述
project_id 是 String 项目ID,获取方法请参见获取项
目ID/账号名/AK/SK。
参数 是否必选 参数类型 描述 face_set_nam
e 是 String 人脸库名称。
请求参数
表7-25 请求 Header 参数
参数 是否必选 参数类型 描述
X-Auth-Token 是 String 用户Token。
Token认证就是在调用API的时 候将Token加到请求消息头,从 而通过身份认证,获得操作API 的权限,响应消息头中X-Subject-Token的值即为Token。
响应参数
状态码:200
表7-26 响应 Body 参数
参数名 参数类型 说明
face_set_info Object 人脸库信息,详见
FaceSetInfo。
调用失败时无此字段。
error_code String 调用失败时的错误码,具
体请参考错误码。
调用成功时无此字段。
error_msg String 调用失败时的错误信息。
调用成功时无此字段。
请求示例
● 请求样例
GET https://{endpoint}/v1/{project_id}/face-sets/showFaceSet 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}
face_set_name = 'showFaceSet'
url = "https://{endpoint}/v1/{project_id}/face-sets/{face_set_name}".format(
endpoint=endpoint,project_id=project_id,face_set_name=face_set_name) response = requests.get(url, headers=headers, verify=False)
print(response.text)
● Java语言请求代码示例(其他语言参照下列示例编写或使用FRS SDK)
import com.huawei.trace.http.apache.httpclient.TraceApacheHttpClientBuilder;
* 使用前需已配置HttpClient jar包。jar包可通过下载SDK获取 */
public class GetFaceSetByFaceSetName {
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和face_set_name需要替换成实际信息。
String url = "https://{{endpoint}}/v1/{{project_id}}/face-sets/{{face_set_name}}";
String token = "对应region的token";
{ "face_set_info": { "face_number": 94, "face_set_id": "T785tx1N", "face_set_name": "showFaceSet", "create_date": "2018-05-10 01:44:39", "face_set_capacity": 10000,
"external_fields": { "number": {
}}
状态码:400 失败响应样例
{ "error_code": "FRS.0202",
"error_msg": "The service has been freeze."
}
状态码
状态码请参见状态码。
错误码
错误码请参见错误码。
7.5.4 删除人脸库
功能介绍
删除人脸库以及其中所有的人脸。人脸库数据为用户隐私数据,该数据无备份,删除 时请谨慎操作。V1版本接口已经停售,该接口仅老用户可用,新用户推荐使用V2版本 API。
前提条件:
请确保您已开通人脸识别服务,具体操作方法请参见申请服务。
URI
DELETE /v1/{project_id}/face-sets/{face_set_name}
表7-27 路径参数
参数 是否必选 参数类型 描述
project_id 是 String 项目ID,获取方法请参见获取项
目ID/账号名/AK/SK。
face_set_nam
e 是 String 人脸库名称。
请求参数
表7-28 请求 Header 参数
参数 是否必选 参数类型 描述
X-Auth-Token 是 String 用户Token。
Token认证就是在调用API的时 候将Token加到请求消息头,从 而通过身份认证,获得操作API 的权限,响应消息头中X-Subject-Token的值即为Token。
响应参数
状态码:200
表7-29 响应 Body 参数
参数名 参数类型 说明
face_set_name String 人脸库名称。
调用失败时无此字段
error_code String 调用失败时的错误码,具体请 参考错误码。
调用成功时无此字段。
error_msg String 调用失败时的错误信息。
调用成功时无此字段。
请求示例
● 请求样例
DELETE https://{endpoint}/v1/{project_id}/face-sets/showFaceSet 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}
face_set_name = 'showFaceSet'
url = "https://{endpoint}/v1/{project_id}/face-sets/
{face_set_name}".format(endpoint=endpoint,project_id=project_id,face_set_name=face_set_name) response = requests.delete(url, headers=headers, verify=False)
print(response.text)
● Java语言请求代码示例(其他语言参照下列示例编写或使用FRS SDK)
* 使用前需已配置HttpClient jar包。jar包可通过下载SDK获取 */
public class DeleteFaceSetByFaceSetName {
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 doDelete(String url, String token, CloseableHttpClient client) {
HttpDelete delete = new HttpDelete(url);
delete.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
//time unit is milliseconds RequestConfig requestConfig =
RequestConfig.custom().setConnectTimeout(3000).setSocketTimeout(3000).build();
delete.setConfig(requestConfig);
delete.setHeader("X-Auth-Token", token);
HttpResponse response = null;
String result = "";
try {
response = client.execute(delete);
HttpEntity responseBody = response.getEntity();
if (responseBody == null) {
System.out.println("the response body is null.");
return result;
} else {
byte[] byteStream = EntityUtils.toByteArray(responseBody);
System.arraycopy(byteStream, 0, new byte[byteStream.length], 0, byteStream.length);
result = new String(byteStream, StandardCharsets.UTF_8);
result = new String(byteStream, StandardCharsets.UTF_8);