Products

SIGN UPLOG IN

Models / OCR for Images & Videos

OCR for Images and Videos

Overview

The OCR model is useful to retrieve the text content of an image or video:

  • For images, the model will return the raw text content in a string.
  • For videos, the model will return the raw text content of each analyzed frame separately. You can change the frequency at which frames are analyzed through the interval parameter.

If you need to moderate the text content, you can skip the OCR step and use the Text in Image Moderation Model instead. This model combines OCR and text moderation in a single step.

Note: the model is optimized for images with 200 words or fewer. If you submit images with more words than that, we recommend you split the image into multiple segments and submit them separately.

Scripts and Recommendations

Scripts

The default script used by the OCR engine is the Latin script, with the english alphabet. You can change this default to another language through the opt_lang parameter. To do so use the following codes:

LanguageCode
English (Latin, default)en
Chinesezh
Japaneseja
Koreanko

Other languages are available upon request. Please get in touch.

Use the model

If you haven't already, create an account to get your own API keys.

You can either upload a public URL to the image, or upload the raw binary image. Here's how to proceed if you choose to share the image's public URL:


curl -X GET -G 'https://api.sightengine.com/1.0/check.json' \
    -d 'models=ocr' \
    -d 'api_user={api_user}&api_secret={api_secret}' \
    --data-urlencode 'url=https://sightengine.com/assets/img/examples/example-text-ocr-3.jpg'


# this example uses requests
import requests
import json

params = {
  'url': 'https://sightengine.com/assets/img/examples/example-text-ocr-3.jpg',
  'models': 'ocr',
  'api_user': '{api_user}',
  'api_secret': '{api_secret}'
}
r = requests.get('https://api.sightengine.com/1.0/check.json', params=params)

output = json.loads(r.text)


$params = array(
  'url' =>  'https://sightengine.com/assets/img/examples/example-text-ocr-3.jpg',
  'models' => 'ocr',
  'api_user' => '{api_user}',
  'api_secret' => '{api_secret}',
);

// this example uses cURL
$ch = curl_init('https://api.sightengine.com/1.0/check.json?'.http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

$output = json_decode($response, true);


// this example uses axios
const axios = require('axios');

axios.get('https://api.sightengine.com/1.0/check.json', {
  params: {
    'url': 'https://sightengine.com/assets/img/examples/example-text-ocr-3.jpg',
    'models': 'ocr',
    'api_user': '{api_user}',
    'api_secret': '{api_secret}',
  }
})
.then(function (response) {
  // on success: handle response
  console.log(response.data);
})
.catch(function (error) {
  // handle error
  if (error.response) console.log(error.response.data);
  else console.log(error.message);
});

The API will then return a JSON response:

            
            
{
    "status": "success",
    "request": {
        "id": "req_22Qd0gUNmRH4GCYLvYtN6",
        "timestamp": 1512483673.1405,
        "operations": 1
    },
    "text": {
        "content": "+1 800 222 2408"
    },
    "media": {
        "id": "med_22Qdfb5s97w8EDuY7Yfjp",
        "uri": "https://sightengine.com/assets/img/examples/example-text-ocr-3.jpg"
    }
}
            
        

Any other needs?

See our full list of Image/Video models for details on other filters and checks you can run on your images and videos. You might also want to check our Text models to moderate text-based content: messages, reviews, comments, usernames...

Was this page helpful?