OCR

FREEMIUM
By API 4 AI | Updated 15 days ago | Visual Recognition
Popularity

9.6 / 10

Latency

1,966ms

Service Level

100%

Health Check

100%

Followers: 19
Resources:
Product Website
API Creator:
Rapid account: API 4 AI
API 4 AI
api4ai
Log In to Rate API
Rating: 4.7 - Votes: 3

README

โญ๏ธ OCR

Examples API4AI Telegram

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.

OCR

Features

๐Ÿ‘‰ Features

  • โœ… Hundreds of supported languages.
  • โœ… Returns text along with coordinates of bounding boxes.
  • โœ… Two recognition modes (find separate words or extract the whole text present in a picture).
  • โœ… Supports multipage PDF files.
  • โœ… Supports two alternative ways to pass images: as a binary file or via url to a public resource.

๐Ÿ‘‰ Demos


๐Ÿ‘‰ Contacts




๐Ÿ›  Endpoints

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.

๐Ÿ‘‰ Get version

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: ...'
Click here to view the response
v1.3.0



๐Ÿ‘‰ Get list of algorithms

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: ...'
Click here to view the response
[
  "simple-text",
  "simple-words"
]



๐Ÿ‘‰ Analyze image and return results

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:

  • as binary file in image field
  • as URL to some public resource in url field

Image 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:

  • Bounding box defines location of text block in normalized coordinates
    (0.0 โ€“ left/top, 1.0 โ€“ right/bottom) in the following notations: [x, y, width, height].
  • Besides bounding boxes, results contain recognized text.

Other fields that are not described above always have the same values.




๐Ÿ“Œ Examples


๐Ÿ‘‰ Recognize the whole text as single block

curl -X 'POST' 'https://ocr43.p.rapidapi.com/v1/results' \
     -H 'X-RapidAPI-Key: ...' \
     -F 'image=@text.jpg'
Click here to view the response
{
  "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"
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

๐Ÿ‘‰ Recognize each word separately

curl -X 'POST' 'https://ocr43.p.rapidapi.com/v1/results?algo=simple-words' \
     -H 'X-RapidAPI-Key: ...' \
     -F 'image=@text.jpg'
Click here to view the response
{
  "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"
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}




โ—๏ธ Possible errors


๐Ÿ‘‰ The service can not process an image

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:

  • Unsupported MIME type
  • Image resolution exceeds limits
  • Corrupted image

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 too big

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.

๐Ÿ‘‰ Missing image

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."}




โ“ F.A.Q.


๐Ÿ‘‰ How to pass an image as binary file?

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'

๐Ÿ‘‰ How to pass an image as URL?

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'

๐Ÿ‘‰ Where to find code examples?

Code examples in Python, C#, JavaScript, Swift and other popular programming languages: https://gitlab.com/api4ai/examples/ocr


๐Ÿ‘‰ Where to try live demo?


๐Ÿ‘‰ I need support

Feel free to contact API4AI team if you have any questions.