This OCR API provides a complete solution for optical character recognition in images. The algorithm’s output is simple and self-sufficient: a detected text block in a bounding box and its recognized text.
This solution suits well as a basis for almost any computer vision application that aims for either all-in-one product or simple OCR goals.
This API is created by API4AI. We build our APIs on a completely cloud technology stack which provides full operability, scalability and stable uptime. Our sole goal is to create out-of-the-box self-contained AI solutions that can easily be integrated into any application with just a few simple steps.
METHOD | URL | DESCRIPTION |
---|---|---|
GET | https://ocr43.p.rapidapi.com/v1/version |
Get a service version. |
GET | https://ocr43.p.rapidapi.com/v1/algos |
Get a list of algorithms. |
POST | https://ocr43.p.rapidapi.com/v1/results |
Perform image analysis and get results. |
Returns an actual version of the service in format vX.Y.Z
where X is the version of API.
PROPERTY | DESCRIPTION |
---|---|
Endpoint | https://ocr43.p.rapidapi.com/v1/version |
Method | GET |
Query parameters | – |
POST parameters | – |
Example
curl -X 'GET' 'https://ocr43.p.rapidapi.com/v1/version' \
-H 'X-RapidAPI-Key: ...'
v1.3.0
Service provides alternative algorithms that may be used for OCR.
The idea behind multiple algorithms is to let clients try different algorithms to get the best one that matches the client’s use case.
This section describes an endpoint that returns all available algorithms that may be used for OCR as list.
PROPERTY | DESCRIPTION |
---|---|
Endpoint | https://ocr43.p.rapidapi.com/v1/algos |
Method | GET |
Query parameters | – |
Example
curl -X 'GET' 'https://ocr43.p.rapidapi.com/v1/algos' \
-H 'X-RapidAPI-Key: ...'
[
"simple-text",
"simple-words"
]
Performs actual image analysis and responds with results.
PROPERTY | DESCRIPTION |
---|---|
Endpoint | https://ocr43.p.rapidapi.com/v1/results |
Method | POST |
Query parameters | mode |
POST parameters | image , url |
Passing image
Image can be passed by posting regular “multipart form data” in two alternative ways:
image
fieldurl
fieldImage must be a regular JPEG or PNG image (with or without transparency) or PDF file.
Usually such images have extensions: .jpg
, .jpeg
, .png
, .pdf
. In case of PDF
each page will be converted to PNG image and processed separately (note: you will be charged for each page!).
The service checks input file by MIME type and accepts the following types:
image/jpeg
image/png
application/pdf
The size of the image file must be less than 16Mb
.
The maximum allowed resolution is 4096x4096
.
Specifying algo
Query parameter algo
is optional and may be used to select one of the algorithms to perform OCR.
By default the service uses simple-text
.
Available modes and expected content of the resulting image:
simple-text
(default) – extract the whole text present in a picture/page.simple-words
– find each word separately.Response schema
For responses with 200
HTTP code the type of response is JSON object with the following schema:
{
"results": [
{
"status": {
"code": ...,
"message": ...
},
"name": ...,
"md5": ...,
"page": ...,
"width": ...,
"height": ...,
"entities": [
{
"kind": "objects",
"name": "text",
"objects": [
{
"box": ...,
"entities": [
{
"kind": "text",
"name": "text",
"text": ...
}
]
}
]
}
]
}
]
}
Primary fields:
Name | Type | Description |
---|---|---|
results[].status.code |
string |
Status code of image processing: ok or failure . |
results[].status.message |
string |
Human readable explanation for the status of image processing. |
results[].name |
string |
Original image name passed in request (e.g. my_image.jpg ). |
results[].md5 |
string |
MD5 sum of original image passed in request. |
results[].page |
int |
Optional page number (presented for multipage inputs only). |
results[].width |
int |
Optional image width (presented for valid inputs only). |
results[].height |
int |
Optional image height (presented for valid inputs only). |
results[].entities[].objects |
array |
Array of detected text blocks. |
results[].entities[].objects[].box |
array |
Text blocks’ bounding box defined by 4 float values. |
results[].entities[].objects[].entities[].text |
string |
Text content of detected block. |
Some details:
0.0
– left/top, 1.0
– right/bottom) in the following notations: [x, y, width, height]
.Other fields that are not described above always have the same values.
curl -X 'POST' 'https://ocr43.p.rapidapi.com/v1/results' \
-H 'X-RapidAPI-Key: ...' \
-F 'image=@text.jpg'
{
"results": [
{
"status": {
"code": "ok",
"message": "Success"
},
"name": "text.jpg",
"md5": "cec303e59f87da6f1e75170f8f65f9fd",
"width": 1500,
"height": 1000,
"entities": [
{
"kind": "objects",
"name": "text",
"objects": [
{
"box": [
0.20666666666666667,
0.301,
0.44333333333333336,
0.342
],
"entities": [
{
"kind": "text",
"name": "text",
"text": "Jane Doe\n1095\nMain Street\nAnytown, US 12345"
}
]
}
]
}
]
}
]
}
curl -X 'POST' 'https://ocr43.p.rapidapi.com/v1/results?algo=simple-words' \
-H 'X-RapidAPI-Key: ...' \
-F 'image=@text.jpg'
{
"results": [
{
"status": {
"code": "ok",
"message": "Success"
},
"name": "text.jpg",
"md5": "cec303e59f87da6f1e75170f8f65f9fd",
"width": 1500,
"height": 1000,
"entities": [
{
"kind": "objects",
"name": "words",
"objects": [
{
"box": [
0.20733333333333334,
0.301,
0.11866666666666667,
0.077
],
"entities": [
{
"kind": "text",
"name": "text",
"text": "Jane"
}
]
},
{
"box": [
0.37066666666666664,
0.305,
0.08466666666666667,
0.075
],
"entities": [
{
"kind": "text",
"name": "text",
"text": "Doe"
}
]
},
{
"box": [
0.22,
0.453,
0.094,
0.044
],
"entities": [
{
"kind": "text",
"name": "text",
"text": "1095"
}
]
},
{
"box": [
0.37933333333333336,
0.43,
0.09466666666666666,
0.061
],
"entities": [
{
"kind": "text",
"name": "text",
"text": "Main"
}
]
},
{
"box": [
0.5006666666666667,
0.433,
0.14933333333333335,
0.061
],
"entities": [
{
"kind": "text",
"name": "text",
"text": "Street"
}
]
},
{
"box": [
0.218,
0.557,
0.16933333333333334,
0.084
],
"entities": [
{
"kind": "text",
"name": "text",
"text": "Anytown"
}
]
},
{
"box": [
0.396,
0.556,
0.015333333333333332,
0.077
],
"entities": [
{
"kind": "text",
"name": "text",
"text": ","
}
]
},
{
"box": [
0.422,
0.553,
0.06466666666666666,
0.08
],
"entities": [
{
"kind": "text",
"name": "text",
"text": "US"
}
]
},
{
"box": [
0.5213333333333333,
0.548,
0.11066666666666666,
0.081
],
"entities": [
{
"kind": "text",
"name": "text",
"text": "12345"
}
]
}
]
}
]
}
]
}
When a client sends an image that can not be processed for some reason(s), the service responds with 200
code and returns a JSON object in the same format as the format for successful analysis. In this case, the results[].status.code
will have failure
value and results[].status.message
will contain relevant explanation.
Example of possible reasons for the issue:
Example response for image with unsupported MIME type:
{
"results": [
{
"status": {
"code": "failure",
"message": "Can not load image."
},
"name": "file.txt",
"md5": "d41d8cd98f00b204e9800998ecf8427e",
"entities": []
}
]
}
Request size is limited by approximately 32Mb
.
When a client sends a request that exceeds this limit, the service responds with 413
code.
The typical reason for exceeding this limit is an overly large image.
Taking into account additional HTTP overhead, we strongly recommend not passing image files of size more than 16Mb
.
Example response for overly big image:
Error: Request Entity Too Large
Your client issued a request that was too large.
When a client sends a request without an image, the service responds with 422
code and returns a JSON object.
Example response for request with missing image:
{"detail":"Missing image or url field."}
Post a file content as a “multipart form data” field named image
.
curl -X 'POST' 'https://ocr43.p.rapidapi.com/v1/results' \
-H 'X-RapidAPI-Key: ...' \
-F 'image=@text.jpg'
Post a URL to file as a “multipart form data” field named url
.
curl -X 'POST' 'https://ocr43.p.rapidapi.com/v1/results' \
-H 'X-RapidAPI-Key: ...' \
-F 'url=https://storage.googleapis.com/api4ai-static/rapidapi/ocr/text.jpg'
Code examples in Python, C#, JavaScript, Swift and other popular programming languages: https://gitlab.com/api4ai/examples/ocr
Feel free to contact API4AI team if you have any questions.