ppu-paddle-ocr
Version:
Lightweight, probably the fastest PaddleOCR SDK in TypeScript. Runs anywhere JavaScript runs: Node.js, Bun, Deno, mobile react-native, web browsers, and browser extensions. Docker & CLI supported. The official SDK is browser-only. Accurate text detection
91 lines (90 loc) • 3.52 kB
TypeScript
import type { Canvas } from "ppu-ocv";
import { BasePaddleOcrService } from "../core/base-paddle-ocr.service.js";
import type { PaddleOptions, RecognizeOptions } from "../interface.js";
import type { FlattenedPaddleOcrResult, PaddleOcrResult } from "../web/paddle-ocr.service.web.js";
/**
* PaddleOcrService - Provides OCR functionality using PaddleOCR models.
* To use this service, create an instance and call the `initialize()` method.
*/
export declare class PaddleOcrService extends BasePaddleOcrService {
/**
* Creates an instance of PaddleOcrService.
* @param options - Configuration options for the service.
*/
constructor(options?: PaddleOptions);
/**
* Fetches a resource from a URL and caches it locally.
* If the resource is already in the cache, it loads it from there.
*/
private _fetchAndCache;
/**
* Loads a resource from a buffer, a file path, a URL, or a default URL.
*/
private _loadResource;
/**
* Not used by the Node service — initialization runs in {@link initialize}.
* @throws Always; call {@link initialize} instead.
*/
protected initSessions(): Promise<void>;
/**
* Initializes the OCR service by loading models and dictionary.
* This method must be called before any OCR operations.
*/
initialize(): Promise<void>;
/**
* Checks if the service has been initialized with models loaded.
*/
isInitialized(): boolean;
/**
* Changes the detection model for the current instance.
* @param model - The new detection model as a path, URL, or ArrayBuffer.
*/
changeDetectionModel(model: ArrayBuffer | string): Promise<void>;
/**
* Changes the recognition model for the current instance.
* @param model - The new recognition model as a path, URL, or ArrayBuffer.
*/
changeRecognitionModel(model: ArrayBuffer | string): Promise<void>;
/**
* Changes the text dictionary for the current instance.
* @param dictionary - The new dictionary as a path, URL, ArrayBuffer, or string content.
*/
changeTextDictionary(dictionary: ArrayBuffer | string): Promise<void>;
/**
* Recognize text in an image, returning flattened results.
*
* @param image - Source image as `ArrayBuffer` or `Canvas`.
* @param options - Must include `flatten: true`.
* @returns Flat list of recognized text items.
*/
recognize(image: ArrayBuffer | Canvas, options: RecognizeOptions & {
flatten: true;
}): Promise<FlattenedPaddleOcrResult>;
/**
* Recognize text in an image, returning line-grouped results.
*
* @param image - Source image as `ArrayBuffer` or `Canvas`.
* @param options - Optional recognition options.
* @returns OCR results grouped by detected text lines.
*/
recognize(image: ArrayBuffer | Canvas, options?: RecognizeOptions & {
flatten?: false;
}): Promise<PaddleOcrResult>;
/**
* Pre-download all default models to the local cache directory.
* Call this before `initialize()` to avoid first-run download delays or
* to warm the cache in CI/CD pipelines and test suites.
*/
static downloadModels(options?: {
verbose?: boolean;
}): Promise<void>;
/**
* Delete all locally cached ONNX model files.
*/
clearModelCache(): void;
/**
* Release all ONNX sessions and free resources.
*/
destroy(): Promise<void>;
}
export default PaddleOcrService;