Choose where you’d like to start

Recognize Text

Description

The zoho.ai.recognizeText task performs OCR (optical character recognition) on the specified file. In other words, it extracts the text from an image or PDF file.

Note: 
  • The processing timeout of this task is 40 seconds. An error will be thrown when this time limit is exceeded. Following are some of the use-cases that contribute a delay in processing time:
    • When the source file is a PDF or image that is heavily concentrated with text.
    • When the source file is a PDF that contains images, the processing time is the sum of the time required to extract the images from the PDF and the time required to perform OCR on the extracted images. This scenario is more likely to have high processing time.
  • The prediction results may not be accurate, which is also the case with any AI prediction. However, we are working on improving this.
  • The prediction results are dynamic. The same script may produce different outcomes at different times based on how much the machine has learned.

Syntax

<response> = zoho.ai.recognizeText(<file>, [<model_type>], [<language>]);

where:

ParamsData typeDescription

<response>

KEY-VALUE

Specifies the text extracted from the given file

<file>

FILE

Specifies the file object that contains the image or PDF file from which the text needs to be extracted.

Note: 

  • The file can be fetched from the cloud using the invokeUrl task. In Zoho Creator, the file uploaded in the file upload field can also be used as a value for this parameter.
  • The file can be a PDF or an image of any valid format.
  • The maximum allowed file size is 20 MB. However, it is recommended to use files with size lesser than 10 MB.

<model_type>

(optional)

TEXT

Specifies one of the supported model types. Appropriate model type can be provided to improve the reading accuracy.

<language>

(optional)

TEXT

Specifies the supported languages that need to be precisely retrieved from the given image. For example, parsing the param value as 'jpn' retrieves the Japanese words from the image as it is.

Say, words with accent marks, for example, from the Romanian language are present in the given image. Specifying this param value as the supported language 'ron' helps the OCR model retrieve the text with all the accent marks intact.

If the param is not specified, the accent marks are removed and the words are retrieved with similar plain English alphabets.

Default value : eng

Note: You can find the allowed model types and supported languages here.

Examples

Example 1 : The following script extracts and returns the English text present in the given image using the OCR model.

 // To fetch the image file from the web
 image = invokeurl
 [
 url: "https://www.mmppicture.co.in/wp-content/uploads/2020/08/Action-Hero-Text-PNG-1080x842.jpg"
 type: GET
 ];
 
 // To extract the English text from the image file using the OCR model
 info zoho.ai.recognizeText(image,"OCR","eng");

where:

image
The FILE that represents the image from which the text needs to be extracted.
"OCR"
The TEXT value that specifies the supported model type that needs to be used.
"eng"
The TEXT value that specifies the supported language which needs to be precisely extracted from the image.

Example 2 : The following script extracts and returns the text present in the given image. The image is retrieved from a specific record's file upload field in your Creator application.

image = Add_Employee[ID == 74069000002332165].File_upload;
aiText = zoho.ai.recognizeText(image,"OCR","ron");        // To extract the Romanian text from the image file using the OCR model. The image used is from a specific record's File_upload field in the Add_Employee form.

where:

aiText
The KEY-VALUE response that represents the text extracted from the image file.
image
The FILE that represents the image from which the text needs to be extracted.
"OCR"
The TEXT value that specifies the supported model type that needs to be used.
"ron"
The TEXT value that specifies the supported language which needs to be precisely extracted from the image.

Response Format

Success Response

  • The success response will be returned in the following format:.

     {"text":"Action Heroes\n\nB orn  i!  Action\n\nwww. MMPPICTURE co.IN\n"}
     
    Note: The \n is the text equivalent of new line. In other words, the text following the \n is present in the next line.

Failure Response

  • The failure response returned for an empty file input will be returned in the following format:

     Execution exception : 'Error due to - 'Internal Exception''
  • The failure response when a file process for more than 40 seconds will be returned in the following format:

     {
     "statusMessage": "Timed out. Please try again with smaller image",
     "status":false
    ​ }
  • The failure response for a file size more than 20 MB will be returned in the following format:

     {
     "statusMessage": "File size exceeds the maximum size",
     "status":false
    ​ }
 

Related Links

Get Started Now

Execute