OCR
10/22/22Less than 1 minute
OCR
ocr.OCR
Handle returned by createOCR. Call release() when you are done to free native memory and threads.
Table of contents
Methods
Methods
detect
▸ detect(image, options?): Promise<OCRResult[]>
Run text detection / recognition on image with optional options.
Example
"nodejs";
const { createOCR } = require("ocr");
const { requestScreenCapture } = require("media_projection");
async function main() {
const ocr = await createOCR();
const capturer = await requestScreenCapture();
const img = await capturer.nextImage();
const results = await ocr.detect(img);
for (const result of results) {
console.log(`text: ${result.text}, confidence: ${result.confidence}`);
console.log(`bounds: (${result.bounds.left}, ${result.bounds.top})`);
}
ocr.release();
capturer.stop();
}
main();Parameters
| Name | Type | Description |
|---|---|---|
image | Image | Input bitmap to recognize. |
options | OCRDetectionOptions | Optional region, max count, rotation detection, etc. |
Returns
Promise<OCRResult[]>
Promise that resolves to an array of OCRResult (text, confidence, bounds, optional rotation).
release
▸ release(): void
Release OCR resources. The runtime may still clean up on exit, but you should call release() as soon as the engine is no longer needed.
Important
OCR engines are heavy; failing to release() can leak memory or keep worker threads alive.
Example
"nodejs";
const { createOCR } = require("ocr");
async function main() {
const ocr = await createOCR();
// const results = await ocr.detect(img);
ocr.release();
}
main();Returns
void
