Updated on 2023-05-06 GMT+08:00

Creating a Facial Image Library

Function

This API is used to create a facial image library for storing facial features. You can create a maximum of 10 facial image libraries. Each library can contain a maximum of 100,000 facial features.

Prerequisites:

Ensure that you have enabled FRS. For detailed operations, see Applying for FRS.

Use standard JSON format in the body of the application/json request.

URI

POST /v2/{project_id}/face-sets

Table 1 Path parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details about how to obtain the ID, see Obtaining the Project ID/Account Name/AK/SK.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token.

During API authentication using a token, the token is added to requests to obtain permissions for calling the API. The value of X-Subject-Token in the response header is the obtained token.

Content-Type

Yes

String

MIME type of the request body. The value is application/json.

Table 3 Request body parameters

Parameter

Type

Mandatory

Description

face_set_name

String

Yes

Name of the facial image library.

Do not start the name of a facial image library with an underscore (_). Otherwise, the Cloud Eye service cannot collect the number of faces.

face_set_capacity

Integer

No

Maximum capacity of a facial image library. The value is an integer multiple of 10,000, for example, 30,000.

The default value is 100000, and the maximum value is 100000. Each user can use 10 facial image libraries. Each library contains 100,000 facial features.

external_fields

Map<String,TypeInfo>

No

Custom data. Custom fields cannot be named vector, bounding_box, external_image_id, face_id, create_time, _id, _all or _source, which are built-in fields.

The uniqueness of JSON strings is not verified. The key value of a custom field contains 1 to 36 characters, and the value of the string type contains 1 to 256 characters. For details, see Customized Fields.

If you want to use custom fields to add faces to the facial image library in subsequent operations, you need to define this field when creating the facial image library.

Table 4 TypeInfo

Parameter

Mandatory

Type

Description

type

No

String

Data type. The value can be string, integer, double, or long.

Response Parameters

Status code: 200

Table 5 Response body parameter

Parameter

Type

Description

face_set_info

FaceSetInfo object

Facial image library information. For details, see FaceSetInfo. This parameter is not included when the API fails to be called.

Table 6 FaceSetInfo

Parameter

Type

Description

face_number

Integer

Number of existing facial features in a facial image library

external_fields

Object

Additional field a user customizes

face_set_id

String

ID of the facial image library. It is a randomly generated string containing eight characters.

face_set_name

String

Name of the facial image library

create_date

String

Creation time

face_set_capacity

Integer

Maximum capacity of a facial image library. If face_set_capacity is not specified when a face image library is created, the face image library can contain a maximum of 100,000 facial features by default.

Status code: 400

Table 7 Response body parameters

Parameter

Type

Description

error_code

String

Error code when calling the API failed. This parameter is not included when the API is successfully called.

error_msg

String

Error message returned after the API fails to be called. This parameter is not included when the API is successfully called.

Example Requests

For details about how to obtain the value of X-Auth-Token, see Authentication.

  • Example request
    POST https://{endpoint}/v2/{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"
        },
        "id" : {
          "type" : "string"
        },
        "number" : {
          "type" : "integer"
        }
      }
    
    }

Example Responses

Status code: 200

Response example (successful request)
{
  "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": 100000,
    "external_fields": {
      "timestamp" : {
        "type" : "long"
      },
      "id" : {
        "type" : "string"
      },
      "number" : {
        "type" : "integer"
      }
    }
  }

}

Status code: 400

Example response (failed request)
{
  "error_code": "FRS.0002",
  "error_msg": "The authentication token is abnormal."
}

Status Code

For details about the status code, see Status Codes.

Error Code

For details about the error code, see Error Codes.