Optical Character Recognition (OCR)

docker pull cargoshipsh/ocr-base-handwritten

The TrOCR model was proposed in TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models by Minghao Li, Tengchao Lv, Lei Cui, Yijuan Lu, Dinei Florencio, Cha Zhang, Zhoujun Li, Furu Wei. TrOCR consists of an image Transformer encoder and an autoregressive text Transformer decoder to perform optical character recognition (OCR). On a moderate CPU it takes only a few seconds to generate the text. This model was contributed by microsoft.

License

The model and the code for the API wrapper is licensed under MIT License.

System Requirements

Minimum: 2GB RAM, 2 vCPU
Recommended: 4GB RAM, 4 vCPU

Usage

Input [POST]

The input expects and image. This can be a URL or a base64 encoded image.

Option 1: URL

{
  "url": "https://images.unsplash.com/photo-1677496891133-f81cc7a4e56e?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=600&q=80"
}

Option 2: Base64

{
  "base64": "/9j/4AAQSkZJRgABAQEASABIAAD/2wBD..."
}

Output

The output is the converted text as a string.

{
  "caption": "a person riding a surfboard on top of a wave in the ocean"
}

You need to set an API Key via the environment variable API_KEY to run the image and set the X-API-KEY header in your request with the same KEY.

Need a more detailed setup guide?

To get more detailed instructions how to get started please check out our quick start guide in the docs.

Example

Make sure you have Docker installed then run the following command:

docker run -p 80:80 --env API_KEY=CHANGE_ME cargoshipsh/ocr-base-handwritten

In a new terminal window, run the following command to call the API

curl -X POST -H 'Content-type: application/json' -H 'X-API-Key: CHANGE_ME' --data '{"url": "https://images.unsplash.com/photo-1677496891133-f81cc7a4e56e?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=600&q=80"}' http://localhost:80

You see the output of the model in the terminal.

{"caption": "a person riding a surfboard on top of a wave in the ocean"}

Need help?

Join our Discord and ask away. We're happy to help where we can!

Join Discord