Skip to content

OCR Recognize File

Type: ocr-recognize  ·  Package: OCR Activities v1.2.5  ·  Output: string

Recognizes and returns all the text of an image file (.png, .jpg, .bmp, .tiff). It is the core activity of the package: read the content of an image or a scanned document and then extract data with expressions.

Runs the image through the Tesseract engine and returns the recognized text, in the reading order detected by the engine (line breaks between lines and blank lines between blocks). Set the text’s language to improve accuracy, and use preprocess to clean up low-quality images. See language and preprocessing.

Recognition runs on the robot’s machine and takes longer the larger the image is; the original file is not changed.

ParameterTypeDefaultDescription
pathstring—Path to the image file (.png, .jpg, .bmp, .tiff).
ParameterTypeDefaultDescription
languagestring"eng"Text language: Tesseract code (eng, spa, eng+spa) or regional tag (es-CO, en-US).
preprocessstring"none"Prior cleanup: none · auto · deskew · binarize. Since 1.2.0.

Returns a string with the recognized text. If the image has no readable text, it returns an empty or almost empty string (only line breaks); check it with isEmpty(trim(text)) or by validating the data you look for.

Read a scanned invoice in Spanish and extract the total:

OCR Recognize File path = scanPath language = "spa" preprocess = "auto" → output: text
Set Variable name = total value = regexFind(text, "(?<=Total:\s*\$?)[\d.,]+")
Log message = "Total read: " + total
MessageCause and fix
File not found.The path does not exist on the robot’s machine.
'path' is required.path is missing or the expression returned nothing.
Tesseract language '…' not found at '…'. Available: [eng, spa].The language code is not installed. Use one of the available ones.
Could not read the image.With preprocess, the file is not a valid image or is damaged.
OpenCV native init failed: …A native preprocessing component is missing on the machine. Reinstall the package or use preprocess = "none".