ocr — text recognition
The ocr module performs on-device optical character recognition. You must install the official OCR plugin from the Auto.js Pro plugin marketplace first.
After createOCR, call release() on the instance when you are done to free native memory and CPU threads.
Table of contents
Classes
Interfaces
Types
Functions
Types
CPUPowerMode
CPUPowerMode: "LITE_POWER_HIGH" | "LITE_POWER_LOW" | "LITE_POWER_FULL" | "LITE_POWER_NO_BIND" | "LITE_POWER_RAND_HIGH" | "LITE_POWER_RAND_LOW"
Controls how OCR threads are pinned to CPU clusters on big.LITTLE ARM SoCs.
LITE_POWER_HIGH— Prefer big cores. If the requested thread count exceeds the big-core count, it is clamped. If the SoC has no big cores or the system rejects affinity (e.g. low battery), binding may fail and the runtime falls back to unpinned mode.LITE_POWER_LOW— Prefer LITTLE cores with the same clamping rule; if no small cluster is exposed, falls back to unpinned mode.LITE_POWER_FULL— Mixed big/LITTLE use; thread count is capped at the total core count when it would otherwise exceed it.LITE_POWER_NO_BIND— Recommended: do not pin threads; let the OS scheduler place work on idle cores.LITE_POWER_RAND_HIGH— Rotate across big cores (approximately every ten inference passes when multiple big cores exist).LITE_POWER_RAND_LOW— Rotate across LITTLE cores with the same cadence.
Functions
createOCR
createOCR(options?: CreateOCROptions): Promise<OCR>
Builds an OCR engine from optional tuning (models, threads, CPUPowerMode, etc.). Defaults are enough for most scripts—call createOCR() with no args if you do not need custom settings.
Example
"nodejs";
const { createOCR } = require("ocr");
const { requestScreenCapture } = require("media_projection");
const { showToast } = require("toast");
const { delay } = require("lang");
async function main() {
const ocr = await createOCR({
models: "default", // higher accuracy, slower model
});
const capturer = await requestScreenCapture();
for (let i = 0; i < 5; i++) {
const capture = await capturer.nextImage();
// First run is usually slower; time depends on resolution, content, and text count.
// Tune threads / CPUPowerMode in createOCR options if needed.
const start = Date.now();
const result = await ocr.detect(capture);
const end = Date.now();
console.log(result);
showToast(`Run ${i + 1}: ${end - start}ms`);
await delay(3000);
}
ocr.release();
}
main().catch(console.error);Parameters
| Name | Type | Description |
|---|---|---|
options? | CreateOCROptions | Model paths, thread count, CPU mode, and related flags. |
Returns
Promise<OCR>
Resolves to a ready-to-use OCR instance.
