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

Text recognition in documents

This method allows you to recognize text in an image.

HOST: https://smarty.mail.ru

ENDPOINT: /api/v1/text/recognize

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
Projects
VK Cloud
mcs
See in the article

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

Parameter
Type
Meaning
images
[]image_meta
Transferred image metadata (required non-empty)
mode
string
Flag parameter: whether to issue a detailed answer, if "detailed", then detailed (the coordinates of the bounding box of the text and confidence are added to the answer), (optional)

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/text/recognize?oauth_token=<ваш токен>&oauth_provider=mcs' \  -H 'accept: application/json' \  -H 'Content-Type: multipart/form-data' \  -F 'file=@docs_recognize_not_doc.jpg;type=image/jpeg' \  -F 'meta={  "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

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
text
string
Recognized text
results
[]line
If "mode":"detailed" is set - an array of answer strings for the page (text, bounding box, confidence)

status parameters:

Parameter
Meaning
0
Successfully
1
Permanent error
2
Temporary error

line parameters:

Parameter
Type
Meaning
line_prob
float32
Line recognition confidence
line_coord
[]float32
Line coordinates - x1,y1, x2, y2 - upper left and lower right points of the enclosing rectangle
words
[]word
Array of recognized response words in a string

word parameters:

Parameter
Type
Meaning
sample
float32
Word recognition confidence
coordinate
[]float32
Word coordinates - x1,y1, x2, y2 - upper left and lower right points of the enclosing rectangle
text
string
Array of recognized response words in a string
lang_prob
float32
Language recognition confidence
language
string
Eng/rus/unknown. Unknown when does not contain letters of the alphabet

Response example

{  "status": 200,  "body": {    "objects": [      {        "status": 0,        "name": "file",        "text": "Когда пришла весна,\nнаступили теплые дни. Там,\nгде раньше лежал снег,\nвесело бегут ручьи. Куда\nни взглянешь, всюду\nрасцветают подснежники.\nЕсли посмотреть на\nвесеннее небо, то можно\nувидеть стаи птиц,\nлетящих с юга. Когда\nпросыпается природа от\nзимнего сна, лес\nнаполняется весенней"      }    ]  },  "htmlencoded": false,  "last_modified": 0}

Additional examples

mode=detailed

Request example:

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

There is no text on the image

Request example:

curl -X 'POST' \  'https://smarty.mail.ru/api/v1/text/recognize?oauth_token=<token>&oauth_provider=mcs' \  -H 'accept: application/json' \  -H 'Content-Type: multipart/form-data' \  -F 'file=@persons_set_error_no_face.jpg;type=image/jpeg' \  -F 'meta={  "mode": "detailed",  "images": [    {      "name": "file"    }  ]}'

Response example:

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

Empty image

Request example:

curl -X 'POST' \  'https://smarty.mail.ru/api/v1/text/recognize?oauth_token=<token>&oauth_provider=mcs' \  -H 'accept: application/json' \  -H 'Content-Type: multipart/form-data' \  -F 'file=@empty.jpg;type=image/jpeg' \  -F 'meta={  "mode": "detailed",  "images": [    {      "name": "file"    }  ]}'

Response example:

{  "status": 400,  "body": "empty image",  "htmlencoded": false,  "last_modified": 0}

Invalid JSON

Request example:

curl -X 'POST' \  'https://smarty.mail.ru/api/v1/text/recognize?oauth_token=<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={  "mode": "detailed",  "images": [    {      "name": "file1"    }  ]}'

Response example:

{  "status": 400,  "body": "could not get image by name file1: http: no such file",  "htmlencoded": false,  "last_modified": 0}