/** * PaddleOCR-JS 增强版 - 类型定义 */ /// /// import type { Image } from "canvas"; declare class PaddleOCR { } /** 坐标点 */ export interface Point { x: number; y: number; } /** 文本框 */ export interface TextBox { id: number; box: Point[]; score: number; } /** 文本行 */ export interface TextLine { text: string; score: number; box?: TextBox; language?: string; } /** OCR 识别结果 */ export interface OCRResult { textDetection: TextBox[]; textRecognition: TextLine[]; duration: { preprocess: number; detection: number; recognition: number; total: number; }; imageWidth?: number; imageHeight?: number; } /** 批量 OCR 结果 */ export interface BatchOCRResult { results: OCRResult[]; totalDuration: number; averageDuration: number; } /** 表格单元格 */ export interface TableCell { box: Point[]; text: string; rowspan: number; colspan: number; row: number; col: number; score: number; } /** 表格识别结果 */ export interface TableResult { structure: TableStructure; cells: TableCell[]; html: string; markdown: string; excel?: string; } /** 表格结构 */ export interface TableStructure { rows: number; cols: number; borders: { top: number[]; bottom: number[]; left: number[]; right: number[]; }; } /** 公式类型 */ export type FormulaType = "inline" | "block" | "inline_tex" | "block_tex" | "html"; /** 公式识别结果 */ export interface FormulaResult { type: FormulaType; latex?: string; tex?: string; html?: string; mathml?: string; text: string; box: Point[]; score: number; } /** 公式识别配置 */ export interface FormulaRecognitionOptions { enableLatex?: boolean; enableMathML?: boolean; enableHtml?: boolean; formulaType?: FormulaType; } /** 布局元素类型 */ export type LayoutType = "text" | "title" | "figure" | "table" | "formula" | "chart" | "header" | "footer" | "footnote" | "equation" | "annotation" | "other"; /** 布局元素 */ export interface LayoutRegion { type: LayoutType; box: Point[]; score: number; content?: string | TableResult | FormulaResult; children?: LayoutRegion[]; } /** 布局分析结果 */ export interface LayoutResult { regions: LayoutRegion[]; pageWidth: number; pageHeight: number; direction?: "ltr" | "rtl" | "ttb"; } /** 条码类型 */ export type BarcodeType = "qr_code" | "data_matrix" | "aztec" | "codabar" | "code_128" | "code_39" | "code_93" | "ean_13" | "ean_8" | "itf" | "pdf_417" | "upc_a" | "upc_e"; /** 条码识别结果 */ export interface BarcodeResult { type: BarcodeType; data: string; format: string; box: Point[]; score: number; } /** 水印类型 */ export type WatermarkType = "text" | "image" | "tiled" | "semi_transparent"; /** 水印信息 */ export interface WatermarkInfo { type: WatermarkType; text?: string; imageUrl?: string; box: Point[]; opacity: number; position: "corner" | "center" | "tiled"; } /** PaddleOCR 配置 */ export interface PaddleOCROptions { modelPath?: string; useTensorflow?: boolean; useONNX?: boolean; useWasm?: boolean; enableDetection?: boolean; detectionModel?: "DB" | "DB++" | "EAST" | "PAN" | string; enableRecognition?: boolean; recognitionModel?: "CRNN" | "SVTR" | "NRTR" | string; language?: LanguageOption; enableTable?: boolean; enableLayout?: boolean; enableFormula?: boolean; enableBarcode?: boolean; enableWatermark?: boolean; tableOptions?: TableRecognitionOptions; formulaOptions?: FormulaRecognitionOptions; maxSideLen?: number; threshold?: number; batchSize?: number; enableGPU?: boolean; numThreads?: number; useMultiScale?: boolean; useAngle_cls?: boolean; enableCache?: boolean; cacheSize?: number; onProgress?: ProgressCallback; onError?: ErrorCallback; } /** 表格识别选项 */ export interface TableRecognitionOptions { enableCoord?: boolean; mergeSpans?: boolean; format?: "html" | "markdown" | "excel"; } /** 语言选项 */ export type LanguageOption = "ch" | "en" | "fr" | "de" | "es" | "pt" | "it" | "ru" | "ja" | "ko" | "ar" | "hi" | string[]; /** 进度回调 */ export type ProgressCallback = (progress: number, stage: string, details?: Record) => void; /** 错误回调 */ export type ErrorCallback = (error: Error, stage?: string) => void; /** 处理模式 */ export type ProcessMode = "text" | "table" | "layout" | "formula" | "barcode" | "all"; /** 处理选项 */ export interface ProcessOptions { mode?: ProcessMode; returnOriginalImage?: boolean; useAngle?: boolean; useDeskew?: boolean; visualize?: boolean; outputPath?: string; } /** 支持的图像输入类型 */ export type ImageSource = HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | ImageData | Image | string | Uint8Array | ArrayBuffer | Buffer | Blob; /** Worker 消息类型 */ export type WorkerMessageType = "init" | "recognize" | "batch" | "terminate" | "progress" | "result" | "error"; /** Worker 消息 */ export interface WorkerMessage { id: string; type: WorkerMessageType; payload?: any; } /** Worker 结果 */ export interface WorkerResult { id: string; success: boolean; result?: OCRResult | TableResult | LayoutResult; error?: string; } /** 可视化选项 */ export interface VisualizeOptions { drawBoxes?: boolean; drawText?: boolean; drawLabels?: boolean; boxColor?: string; textColor?: string; boxThickness?: number; fontSize?: number; fontFamily?: string; includeConfidence?: boolean; } /** WorkerHelper 构造函数 */ export interface WorkerHelperConstructor { new (options: PaddleOCROptions, workerUrl?: string): any; } /** ResultVisualizer 构造函数 */ export interface ResultVisualizerConstructor { new (container: string | HTMLElement, options?: VisualizeOptions): any; } /** LightVisualizer 构造函数 */ export interface LightVisualizerConstructor { new (container: string | HTMLElement, options?: VisualizeOptions): any; } /** PaddleOCR 静态接口 */ export interface PaddleOCRStatic { new (options?: PaddleOCROptions): PaddleOCR; version: string; WorkerHelper: WorkerHelperConstructor; ResultVisualizer: ResultVisualizerConstructor; LightVisualizer: LightVisualizerConstructor; getSupportedLanguages(): string[]; getModelInfo(): ModelInfo; isSupported(): Promise; } /** 模型信息 */ export interface ModelInfo { detection: string[]; recognition: string[]; table: string[]; formula: string[]; layout: string[]; } /** PaddleOCR 实例接口 */ export interface PaddleOCRInstance { init(): Promise; recognize(image: ImageSource, options?: ProcessOptions): Promise; recognizeTable(image: ImageSource, options?: ProcessOptions): Promise; analyzeLayout(image: ImageSource, options?: ProcessOptions): Promise; recognizeFormula(image: ImageSource, options?: ProcessOptions): Promise; detectBarcodes(image: ImageSource): Promise; detectWatermarks(image: ImageSource): Promise; recognizeBatch(images: ImageSource[], options?: ProcessOptions): Promise; visualize(result: OCRResult, image: ImageSource, options?: VisualizeOptions): Promise; dispose(): Promise; getStats(): OCRStats; } /** OCR 统计信息 */ export interface OCRStats { totalRequests: number; successfulRequests: number; failedRequests: number; averageDuration: number; cacheHits: number; cacheMisses: number; } /** OCR 错误类型 */ export declare class OCRError extends Error { code: string; stage?: string; details?: any; constructor(message: string, code: string, stage?: string, details?: any); } export declare const ErrorCode: { readonly INIT_FAILED: "INIT_FAILED"; readonly MODEL_NOT_FOUND: "MODEL_NOT_FOUND"; readonly DETECTION_FAILED: "DETECTION_FAILED"; readonly RECOGNITION_FAILED: "RECOGNITION_FAILED"; readonly INVALID_IMAGE: "INVALID_IMAGE"; readonly NOT_INITIALIZED: "NOT_INITIALIZED"; readonly WORKER_ERROR: "WORKER_ERROR"; readonly UNSUPPORTED_FORMAT: "UNSUPPORTED_FORMAT"; readonly OUT_OF_MEMORY: "OUT_OF_MEMORY"; readonly TIMEOUT: "TIMEOUT"; }; export {};