Implementation:A9T9 RPA runOCR
| Knowledge Sources | |
|---|---|
| Domains | OCR, Text_Recognition |
| Last Updated | 2026-10-22 00:00 GMT |
Overview
Concrete tool for performing OCR text recognition via cloud (ocr.space) and local (XModule2 ocrs) engines, provided by the Ui.Vision OCR service.
Description
The runOCR function (`src/services/ocr/index.ts`) performs OCR text recognition using the ocr.space cloud API. It sends the screenshot image (as a data URI or file blob) along with the API key, language, engine selection (1/2/3), and overlay requirement to the ocr.space endpoint. It handles timeouts, retries, and response parsing into an `OcrResponse` with parsed text and positioned word bounding boxes.
The runOCRLocal function performs OCR locally via the XModule2 native host's `ocr_image` RPC. It supports the cross-platform `ocrs` engine (same recognition on every OS, models auto-installed on first use) or the OS-native engine (Windows.Media.Ocr / Apple Vision). The local result is adapted to the ocr.space schema so all callers parse uniformly.
Usage
Call `runOCR` for cloud-based OCR (requires an ocr.space API key configured in settings). Call `runOCRLocal` for on-device OCR (requires the Desktop Automation XModule). The OCR command module (`src/modules/ocr.ts`) selects between them via `getOcrResponse`.
Code Reference
Source Location
- Repository: A9T9/RPA
- File: src/services/ocr/index.ts
- Lines: L132-L197 (runOCRLocal, runOCRLocalViaXModule2), L198-L400 (runOCR)
Signature
export function runOCR(options: RunOCROptions): Promise<OcrResponse>
export function runOCRLocal(options: RunOCROptions): Promise<any>
interface RunOCROptions {
image: FileObject | string, // Image to OCR (file or data URI)
language: OCRLanguage, // Language code
engine: number, // ocr.space engine (1, 2, or 3)
isOverlayRequired: boolean, // Return word positions
isTable?: boolean,
scale?: string,
singleApiTimeout: number,
totalTimeout: number,
localEngine?: 'ocrs', // For runOCRLocal: cross-platform engine
getApiUrlAndKey: () => Promise<{ url: string, key: string }>,
willSendRequest?: Function,
didGetResponse?: Function
}
Import
import { runOCR, runOCRLocal } from '@/services/ocr'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| image | string | Yes | Image to OCR (file blob or data URI string) |
| language | string | Yes | OCR language code (e.g. 'eng', 'deu') |
| engine | number | No | ocr.space engine: 1 (fastest), 2 (clicking), 3 (best text) |
| isOverlayRequired | boolean | Yes | If true, return word bounding boxes |
| singleApiTimeout | number | Yes | Per-request timeout in ms |
| totalTimeout | number | Yes | Total timeout across retries in ms |
Outputs
| Name | Type | Description |
|---|---|---|
| OcrResponse | object | ParsedResults with TextOverlay (word positions), ParsedText, OCRExitCode |
Usage Examples
Cloud OCR via ocr.space
import { runOCR } from '@/services/ocr'
const response = await runOCR({
image: screenshotDataURI,
language: 'eng',
engine: 2,
isOverlayRequired: true,
scale: 'true',
singleApiTimeout: 30000,
totalTimeout: 120000,
getApiUrlAndKey: async () => ({ url: 'https://api.ocr.space/parse/image', key: 'YOUR_KEY' })
})
const text = response.ParsedResults[0].ParsedText
console.log('Recognized:', text)
Local OCR via XModule2
import { runOCRLocal } from '@/services/ocr'
const response = await runOCRLocal({
image: screenshotDataURI,
language: 'eng',
localEngine: 'ocrs'
})