import type { InferenceSession } from "onnxruntime-common"; import type { Box, DebuggingOptions, ProcessingEngine, RecognitionOptions } from "../interface.js"; import type { CoreCanvas, PlatformProvider } from "./platform.js"; /** * A single recognized text item with its bounding box and confidence. */ export interface RecognitionResult { /** The recognized text string. */ text: string; /** Bounding box of the text region in the original image coordinates. */ box: Box; /** Recognition confidence score (0–1). */ confidence: number; } /** * Service for detecting and recognizing text in images */ export declare class BaseRecognitionService { protected readonly options: RecognitionOptions; protected readonly debugging: DebuggingOptions; protected readonly session: InferenceSession; protected readonly platform: PlatformProvider; protected readonly engine: ProcessingEngine; private static readonly BLANK_INDEX; private static readonly UNK_TOKEN; private static readonly MIN_CROP_WIDTH; constructor(platform: PlatformProvider, session: InferenceSession, options?: Partial, debugging?: Partial, engine?: ProcessingEngine); /** * Logs a message if verbose debugging is enabled */ protected log(message: string): void; /** * Main method to run text recognition on an image with detected regions * @param image The original image buffer or image in Canvas * @param detection Array of bounding boxes from text detection * @param charactersDictionary Optional custom character dictionary * @returns Array of recognition results with text and bounding box, sorted in reading order */ run(image: ArrayBuffer | CoreCanvas, detection: Box[], charactersDictionary?: string[]): Promise; /** * Filter out invalid boxes */ private filterValidBoxes; /** * Process all valid boxes in parallel using Promise.all */ private processBoxesInParallel; /** * Process a single text box */ private processBox; /** * Sort recognition results by reading order (top to bottom, left to right) */ private sortResultsByReadingOrder; /** * Validates if a bounding box has valid dimensions */ private isValidBox; /** * Crops a region from the source canvas based on bounding box */ private cropRegion; /** * Saves a debug image of the cropped region */ private saveDebugCrop; /** * Logs details about the processing of a text region */ private logProcessingDetails; /** * Recognizes text in a cropped canvas region */ private recognizeText; /** * Preprocesses a cropped image for the recognition model */ private preprocessImage; /** * Creates a normalized image tensor from a CanvasProcessor */ private createImageTensor; /** * Creates a normalized image tensor from a canvas (shared by both engines) */ private createImageTensorFromCanvas; /** * Runs the ONNX inference session with the prepared tensor */ private runInference; /** * Decodes the results from the model output tensor */ private decodeResults; /** * Performs greedy decoding on CTC model output logits */ private ctcGreedyDecode; /** * Appends the appropriate character to the decoded text */ private appendCharacterToText; /** * Finds the class with maximum probability for a given timestep */ private findMaxProbabilityClass; /** * Checks if the predicted class index is valid for the character dictionary */ private isValidDictionaryIndex; }