import type { InferenceSession } from "onnxruntime-common"; import type { Box, DebuggingOptions, DetectionOptions, ProcessingEngine } from "../interface.js"; import type { CoreCanvas, PlatformProvider } from "./platform.js"; /** * Result of preprocessing an image for text detection. * * Contains the normalized float tensor, dimensions, and scale factors * needed to map detection output back to original image coordinates. */ export interface PreprocessDetectionResult { /** Normalized float tensor (CHW layout, 3 channels). */ tensor: Float32Array; /** Width of the padded/resized tensor in pixels. */ width: number; /** Height of the padded/resized tensor in pixels. */ height: number; /** Scale factor applied during resize (`resized / original`). */ resizeRatio: number; /** Original image width before preprocessing. */ originalWidth: number; /** Original image height before preprocessing. */ originalHeight: number; } /** * Service for detecting text regions in images */ export declare class BaseDetectionService { protected readonly options: DetectionOptions; protected readonly debugging: DebuggingOptions; protected readonly session: InferenceSession; protected readonly platform: PlatformProvider; protected readonly engine: ProcessingEngine; private static readonly NUM_CHANNELS; private lastDetectionCanvas; 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 detection on an image * @param image ArrayBuffer of the image or platform-specific Canvas */ run(image: ArrayBuffer | CoreCanvas): Promise; /** * Preprocess an image for text detection */ private preprocessDetection; /** * Calculate dimensions for resizing the image */ private calculateResizeDimensions; /** * Create a padded canvas from the resized image */ private createPaddedCanvas; /** * Convert an image to a normalized tensor for model input */ private imageToTensor; /** * Run the detection model inference */ private runInference; /** * Convert a tensor to a canvas for visualization and processing */ private tensorToCanvas; /** * Process detection results to extract bounding boxes */ private postprocessDetection; /** * Post-process detection using OpenCV contours (v4-compatible, more accurate) */ private postprocessWithOpenCV; /** * Extract boxes from OpenCV contours */ private extractBoxesFromContours; /** * Post-process detection using canvas-native region detection */ private postprocessWithCanvasNative; /** * Extract boxes from detected regions (native canvas implementation) */ private extractBoxesFromRegions; /** * Apply padding to a rectangle */ private applyPaddingToRect; /** * Convert coordinates from resized image back to original image */ private convertToOriginalCoordinates; /** * Debug the detection canvas in binary image format (thresholded) */ private debugDetectionCanvas; /** * Debug the bounding boxes by drawing a rectangle onto the original image */ private debugDetectedBoxes; }