VK Cloud logo
Updated at March 20, 2024   06:18 AM

Face recognition

HOST: https://smarty.mail.ru

Four API methods are used for face recognition:

  • set (/api/v1/persons/set);
  • recognize (/api/v1/persons/recognize);
  • delete (/api/v1/persons/delete);
  • truncate (/api/v1/persons/truncate).

Let's consider each of them in more detail.

Set

This method allows you to establish a link between a given photo and a specific person_id.

Request

Authorization data is passed in the query string:

Parameter
Type
Meaning
oauth_token
string
OAuth2 access token (required non-empty)
oauth_provider
string
OAuth2 provider (required non-empty)

Supported OAuth2 providers:

Provider
oauth_provider value
Getting a token
VK Cloud
mcs
See in article

Request parameters are passed in JSON format in the request body with name="meta":

Parameter
Type
Meaning
space
string
Filenames to match files in request and response (required non-empty)
images
[]image_meta
ID matched to the person in the photo (required non-empty)

The space parameter is used to avoid intersections by person. So person1 from space 0 and person1 from space 1 are different. For applications that solve different problems, it makes sense to use different values ​​of space.

A client can have up to 10 different spaces. Space values ​​range from 0 to 9. If the limit is exceeded, an error will be returned.

image_meta parameters:

Parameter
Type
Meaning
name
string
Filenames to match files in request and response (required non-empty)
person_id
int
ID associated with the person in the photo (required non-empty)

Request example

curl -X 'POST' "https://smarty.mail.ru/api/v1/persons/set?oauth_token=<ваш токен>&oauth_provider=mcs"      \  -H 'accept: application/json' \  -H 'Content-Type: multipart/form-data' \  -F 'file=@persons_set_ok.jpg;type=image/jpeg' \  -F 'meta={  "space": "5",  "images": [    {      "name": "file",      "person_id": 1    }  ]}'

Response

Parameter
Type
Meaning
status
int
200 in case of successful communication with the Vision
body
response
Response body

response parameters:

Parameter
Type
Meaning
objects
[] object
array of responses for each file

object parameters:

Parameter
Type
Meaning
status
enum
Execution result
error
string
Text description of the error (optional)
name
string
File name to match files in request and response

status parameters:

Parameter
Meaning
0
Successfully
1
Array of found document types per page
2
Temporary error

Answer example

{  "status": 200,  "body": {    "objects": [      {        "status": 0,        "name": "file"      }    ]  },  "htmlencoded": false,  "last_modified": 0}

Additional examples

Recognize

This method allows you to recognize a person from a given photo. If no match is found, a new person will be added.

Request

AuthorizationThis data is passed in the query string:

Parameter
Type
Meaning
oauth_token
string
OAuth2 access token (required non-empty)
oauth_provider
string
OAuth2 provider (required non-empty)

Supported OAuth2 providers:

Provider
oauth_provider value
Getting a token
VK Cloud
mcs
See in article

Request parameters are passed in JSON format in the request body with name="meta":

Parameter
Type
Default
Meaning
space
string
--
Numeric identifier used to avoid person intersections (required non-empty)
create_new
bool
false
Whether to add a new person if no matches were found
images
[]image_meta
--
Transferred image metadata (required non-empty)

For a description of the space parameter, see the section of the Set method.

image_meta parameters:

Parameter
Type
Meaning
name
string
Filenames to match files in request and response (required non-empty)

Images are passed in the body of the request, the values ​​of the name field must match those passed in images.

Request example

curl -X 'POST' \  'https://smarty.mail.ru/api/v1/persons/recognize?oauth_token=<ваш токен>&oauth_provider=mcs' \  -H 'accept: application/json' \  -H 'Content-Type: multipart/form-data' \  -F 'file=@persons_recognize_ok_person_in_db.jpg;type=image/jpeg' \  -F 'meta={  "space": "5",  "create_new": false,  "images": [    {      "name": "file"    }  ]}'

Response

Parameter
Type
Meaning
status
int
200 in case of successful interaction with the Vision servers
body
response
Response body

response parameters:

Parameter
Type
Meaning
objects
[] object
Array of responses for each file
aliases_changed
bool
Have aliases changed

object parameters:

Parameter
Type
Meaning
status
enum
Execution result
error
string
Text description of the error (optional)
name
string
File name to match files in request and response
persons
[]person
List of persons found in the photo

status parameters:

Parameter
Meaning
0
successfully
1
permanent error
2
temporary error

person parameters:

Parameter
Type
Meaning
tag
string
Found person ID
coordinate
[]int
Found face coordinates [left x, top y, right x, bottom y]
aliases
[]string
Array of similar persons (optional)
confidence
float
Degree of confidence of the face detector that the found image is a face (from 0 to 1)
similarity
float
The degree of similarity of the found face with the person in the database
awesomeness
float
Conditional "coolness" of the photo (from 0 to 1)

For the second model only:

Parameter
Type
Meaning
sex
string
Person's gender ["female", "male"]
age
float
Person's age
emotions
string
Person's emotions: "Neutral", "Happiness", "Sadness", "Surprise", "Fear", "Disgust", "Anger", "Contempt"
valence
float
The level of approval by a person of the situation in which he is [-1;1]
arousal
float
Level of human involvement [-1 - sleepy, inactive person; 1 - active person]

The value of tag may equal undefined if the value of create_new in the request was false and no corresponding person was found in the database for the provided image.

Answer example

{  "status": 200,  "body": {    "objects": [      {        "status": 0,        "name": "file",        "persons": [          {            "tag": "person1",            "coord": [              567,              376,              992,              931            ],            "confidence": 0.99917,            "awesomeness": 0.4894,            "similarity": 0.9721,            "sex": "male",            "emotion": "Neutral",            "age": 34,            "valence": -0.3236,            "arousal": 0.185,            "frontality": 0.8921,            "visibility": 0.9985          }        ]      }    ]  },  "htmlencoded": false,  "last_modified": 0}

Additional examples

Delete

This method allows you to remove the association between a photo and person_id.

Request

Authorization data is passed in the query string:

Parameter
Type
Meaning
oauth_token
string
OAuth2 access token (required non-empty)
oauth_provider
string
OAuth2 provider (required non-empty)

Supported OAuth2 providers:

Provider
oauth_provider value
Getting a token
VK Cloud
mcs
See in article

Request parameters are passed in JSON format in the request body with name="meta":

Parameter
Type
Meaning
space
string
numeric identifier used to avoid person collisions (required non-empty)
images
[]image_meta
metadata of transferred images (required non-empty)

For a description of the space parameter, see the section of the Set method.

image_meta parameters:

Parameter
Type
Meaning
name
string
Filenames to match files in request and response (required non-empty)
person_id
int
ID associated with the person in the photo (required non-empty)

Images are passed in the body of the request, the values ​​of the name field must match those passed in images.

Request example

curl -X 'POST' \  'https://smarty.mail.ru/api/v1/persons/delete?oauth_token=<ваш токен>&oauth_provider=mcs' \  -H 'accept: application/json' \  -H 'Content-Type: multipart/form-data' \  -F 'meta={  "space": "5",  "images": [    {      "name": "aaa",      "person_id": 1    }  ]}'

Response

Parameter
Type
Meaning
status
int
200 in case of successful interaction with the Vision servers
body
response
Response body

response parameters:

Parameter
Type
Meaning
objects
[] object
Array of responses for each file

object parameters:

Parameter
Type
Meaning
status
enum
Execution result
error
string
Text description of the error (optional)
name
string
File name to match files in request and response

status parameters:

Parameter
Meaning
0
Successfully
1
Permanent error
2
Temporary error

Answer example

{  "status": 200,  "body": {    "objects": [      {        "status": 0,        "name": "aaa"      }    ]  },  "htmlencoded": false,  "last_modified": 0}

Additional examples

Truncate

This method allows you to completely clear the space.

Request

Authorization data is passed in the query string:

Parameter
Type
Meaning
oauth_token
string
OAuth2 access token (required non-empty)
oauth_provider
string
OAuth2 provider (required non-empty)

Supported OAuth2 providers:

Provider
oauth_provider value
Getting a token
VK Cloud
mcs
See in article

Request parameters are passed in JSON format in the request body with name="meta":

Parameter
Type
Meaning
space
string
Numeric identifier used to avoid person collisions (required non-empty)

For a description of the space parameter, see the section of the Set method.

This request does not require the transfer of images.

Request example

curl -X 'POST' \  'https://smarty.mail.ru/api/v1/persons/truncate?oauth_token=<ваш токен>&oauth_provider=mcs' \  -H 'accept: application/json' \  -H 'Content-Type: multipart/form-data' \  -F 'meta={  "space": "5"}'

Response

Parameter
Type
Meaning
status
int
200 in case of successful interaction with the Vision servers
body
response
Response body

Answer example

{  "status": 200,  "body": {},  "htmlencoded": false,  "last_modified": 0}

Additional examples