Einstein Platform Services

Use the OCR Model to Detect Text

In this walkthrough, you use the Einstein OCR API to pass an image into the OCR model. The model detects any text in the image and returns the text and other details in the response.

Step 1: Get a Token

A valid JWT token is required to make API calls.

  1. Sign up for an account. Follow the steps in What You Need to Call the API to sign up for an Einstein Platform Services account and download your private key file. If you already have an account, you can skip this step.

  2. Find your key file. If you already created an account, locate the einstein_platform.pem file that you downloaded as part of that process. This file contains your private key.

  3. Install cURL. You use the cURL command-line tool throughout the following walkthrough. The tool is installed by default on Linux and OSX. If you don’t already have it installed, download it from https://curl.haxx.se/download.html. Alternatively, you can use Postman to make API calls.

  4. Get a token. The Einstein Intent API uses the OAuth 2.0 JWT bearer token flow for authorization. Use the token page to upload your key file and generate a JWT token.

Step 2: Call the OCR Model

Copy and paste the following cURL call into a text editor and replace <TOKEN> with your valid token. This command works on Windows. If you're on Linux, it can require some format changes, such as from double quotes to single quotes. This command uses the model OCRModel.

curl -X POST -H "Authorization: Bearer <TOKEN>" -F sampleLocation="https://www.publicdomainpictures.net/pictures/240000/velka/emergency-evacuation-route-signpost.jpg" -F modelId="OCRModel" https://api.einstein.ai/v2/vision/ocr

The URL references this image.

You get a response like the following JSON.

{
  "task": "text",
  "probabilities": [
    {
      "probability": 0.99937266,
      "label": "ROUTE",
      "boundingBox": {
        "minX": 582,
        "minY": 685,
        "maxX": 1151,
        "maxY": 815
      }
    },
    {
      "probability": 0.99471515,
      "label": "EMERGENCY",
      "boundingBox": {
        "minX": 361,
        "minY": 208,
        "maxX": 1383,
        "maxY": 346
      }
    },
    {
      "probability": 0.99469215,
      "label": "EVACUATION",
      "boundingBox": {
        "minX": 331,
        "minY": 438,
        "maxX": 1401,
        "maxY": 570
      }
    }
  ],
  "object": "predictresponse"
}

Updated 4 months ago

Use the OCR Model to Detect Text


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.