import type { InferenceSession } from "onnxruntime-common"; import type { PaddleOptions, RecognizeOptions } from "../interface.js"; import { BaseDetectionService } from "./base-detection.service.js"; import { BaseRecognitionService, type RecognitionResult } from "./base-recognition.service.js"; import type { CoreCanvas, PlatformProvider } from "./platform.js"; /** * OCR result grouped by detected text lines. * * Each entry in `lines` is an array of recognized words on the same line, * sorted left-to-right. */ export interface PaddleOcrResult { /** Full extracted text with lines separated by newlines. */ text: string; /** Recognition results grouped by line, in reading order. */ lines: RecognitionResult[][]; /** Average confidence across all recognized items (0–1). */ confidence: number; } /** * OCR result as a flat list of recognized text items. * * Convenience alternative to {@link PaddleOcrResult} when line grouping * is not needed (e.g. for search indexing or simple display). */ export interface FlattenedPaddleOcrResult { /** Full extracted text as a single space-separated string. */ text: string; /** All recognized items in reading order. */ results: RecognitionResult[]; /** Average confidence across all recognized items (0–1). */ confidence: number; } /** Base URL for downloading default PaddleOCR model files from GitHub. */ export declare const MODEL_BASE_URL = "https://media.githubusercontent.com/media/PT-Perkasa-Pilar-Utama/ppu-paddle-ocr-models/main"; /** Base URL for downloading default PaddleOCR dictionary files from GitHub. */ export declare const DICT_BASE_URL = "https://raw.githubusercontent.com/PT-Perkasa-Pilar-Utama/ppu-paddle-ocr-models/main"; /** * Abstract base class for platform-agnostic PaddleOCR service. * * Concrete implementations (`PaddleOcrService` for Node, Web, etc.) * extend this class and provide a {@link PlatformProvider}. */ export declare abstract class BasePaddleOcrService { protected options: PaddleOptions; protected detectionSession: InferenceSession | null; protected recognitionSession: InferenceSession | null; protected detector: BaseDetectionService | null; protected recognitor: BaseRecognitionService | null; protected readonly platform: PlatformProvider; constructor(platform: PlatformProvider, options?: PaddleOptions); protected log(message: string): void; protected abstract initSessions(): Promise; /** * Run the full OCR pipeline (detection → recognition) on an image. * * @param image - The source image as an `ArrayBuffer`, platform canvas, or URL/path string. * @param options - Per-call options such as `flatten`, `noCache`, and custom `dictionary`. * @returns Grouped or flattened OCR results depending on `options.flatten`. */ recognize(image: ArrayBuffer | CoreCanvas | string, options?: RecognizeOptions): Promise; private flattenResults; private groupResultsByLine; }