import type { InferenceSession } from "onnxruntime-common"; import type { DocLayoutOptions, DocLayoutResult, DocLayoutResultWithMasks } from "../interface.js"; import type { CoreCanvas, PlatformProvider } from "./platform.js"; /** * Abstract base class for platform-agnostic document layout analysis. * * Concrete implementations (`DocLayoutService` for Node/Web) extend this * class and provide a {@link PlatformProvider}. */ export declare abstract class BaseDocLayoutService { protected options: DocLayoutOptions; protected session: InferenceSession | null; protected readonly platform: PlatformProvider; constructor(platform: PlatformProvider, options?: DocLayoutOptions); protected log(message: string): void; protected abstract initSessions(): Promise; /** * Run layout analysis on an image. * * The model outputs regions in reading order, preserving the document's * natural reading structure. * * @param image - The source image as an `ArrayBuffer` or platform canvas. * @returns Layout analysis result with detected regions in reading order. */ analyze(image: ArrayBuffer | CoreCanvas): Promise; /** Prepare a canvas from an ArrayBuffer image. */ private prepareCanvas; /** * Resize, normalize, and convert image to CHW float32 tensor. */ private preprocess; /** * Parse raw model output into LayoutBox array sorted by reading order. * * V2 boxes: [cls_id, score, x1, y1, x2, y2, reading_order, ?] * V3 boxes: [cls_id, score, x1, y1, x2, y2, reading_order] * * Column 6 contains the model's baked-in reading order index. * After sorting, cross-class NMS removes overlapping duplicate detections. */ private postprocess; /** * Merge same-label contained boxes. * * When two boxes share the same label and one is largely contained inside * the other (IoMin > 0.6), the inner box is dropped since the outer box * already covers that content. */ private mergeSameLabelContained; /** * Cross-class Non-Maximum Suppression using IoU. * * Suppresses near-duplicate boxes (same spatial region, different labels). * A high IoU threshold (0.8) ensures only true duplicates are removed. */ private applyCrossClassNMS; /** Intersection over Union between two [x1, y1, x2, y2] boxes. */ private computeIoU; /** Intersection over Minimum area — detects containment. */ private computeIoMin; /** * Extract per-region masks from V3 output, filtered by threshold. */ private extractMasks; /** * Draw annotated bounding boxes on the original image and save to disk. */ private debugAnnotatedImage; }