//#region src/utils/image.d.ts
interface CropOptions {
  x: number;
  y: number;
  width: number;
  height: number;
}
interface ResizeOptions {
  width?: number;
  height?: number;
  filter?: "triangle";
}
interface PaddingOptions {
  padding?: number;
  vertical?: number;
  horizontal?: number;
  top?: number;
  bottom?: number;
  left?: number;
  right?: number;
  color?: number[];
}
interface TensorOptions {
  mean_values: [number, number, number];
  norm_values: [number, number, number];
}
interface DilateOptions {
  norm?: "LInf";
  k?: number;
}
interface ThresholdOptions {
  threshold?: number;
}
interface ContoursOptions {
  minArea?: number;
}
interface RectOptions {
  x: number;
  y: number;
  width: number;
  height: number;
  lineWidth?: number;
  color?: number[];
}
declare class Image {
  width: number;
  height: number;
  data: Uint8Array;
  depth: 8;
  channels: number;
  /**
   * 创建一个新的 Image 实例。
   * @param width 图像的宽度
   * @param height 图像的高度
   * @param data 图像数据，Uint8Array
   */
  constructor(width: number, height: number, channels: number, data: Uint8Array);
  /**
   * 裁剪
   */
  crop(options: CropOptions): Image;
  /**
   * 将图片缩放到指定的尺寸w
   * @param options
   */
  resize(options: ResizeOptions): Image;
  /**
   * 为图片添加指定颜色的边距，默认为透明的
   * @param options
   */
  padding(options: PaddingOptions): Image;
  /**
   * 将当前图像转换为张量格式，以便输入到onnx模型
   * @param options
   */
  tensor(options: TensorOptions): Float32Array;
  /**
   * 灰度图阈值方法，大于阈值的像素点设为255，小于等于阈值的设为0
   * @param options
   */
  threshold(options: ThresholdOptions): Image;
  /**
   * 膨胀操作，使用指定的范数和核大小
   * 进行处理的图片像素是0和255，膨胀255的像素点
   * 返回一个新的图片
   * @param options
   */
  dilate(options?: DilateOptions): Image;
  /**
   * 获取图像中的轮廓
   * @returns
   */
  contours(options?: ContoursOptions): Box[];
  /**
   * 在图像上绘制矩形，支持线宽
   * @param x 左上角x
   * @param y 左上角y
   * @param width 矩形宽度
   * @param height 矩形高度
   * @param color 颜色 [r,g,b,a]
   * @param lineWidth 线宽
   */
  rect(options: RectOptions): void;
}
//#endregion
//#region src/processor/recognition.d.ts
interface RecognitionResult {
  text: string;
  box: Box;
  confidence: number;
}
/**
 * Service for detecting and recognizing text in images
 */
declare class RecognitionService {
  private readonly options;
  private readonly session;
  private readonly ortModule;
  constructor(ortModule: OrtModule, session: OrtInferenceSession, options?: Partial<RecognitionRuntimeOptions>);
  /**
   * 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
   * @returns Array of recognition results with text and bounding box, sorted in reading order
   */
  run(image: Image, detection: Box[], options?: RecognitionOptions): Promise<RecognitionResult[]>;
  private resolveRuntimeOptions;
  private resolveOrderingOptions;
  /**
   * Process a single text box
   */
  private processBox;
  /**
   * Sort recognition results by reading order (top to bottom, left to right)
   */
  private sortBoxesByReadingOrder;
  private createProgress;
  /**
   * Runs the ONNX inference session with the prepared tensor
   */
  private runInference;
  private ctcLabelDecode;
}
//#endregion
//#region src/interface.d.ts
interface ImageInput {
  width: number;
  height: number;
  data: Uint8Array;
}
/**
 * Runtime parameters for text detection.
 */
interface DetectionRuntimeOptions {
  padding?: number;
  /**
   * Per-channel mean values used to normalize input pixels [R, G, B].
   * @default [123.675, 116.28, 103.53]
   */
  mean?: [number, number, number];
  /**
   * Per-channel standard deviation values used to normalize input pixels [R, G, B].
   * @default [0.017124753831663668, 0.01750700280112045, 0.015378700499807768]
   */
  stdDeviation?: [number, number, number];
  /**
   * Maximum dimension (longest side) for input images, in pixels.
   * Images above this size will be scaled down, maintaining aspect ratio.
   * @default 960
   */
  maxSideLength?: number;
  /**
   * Padding applied to each detected box vertically as a fraction of its height.
   * @default 0.4
   */
  paddingBoxVertical?: number;
  /**
   * Padding applied to each detected box horizontally as a fraction of its height.
   * @default 0.6
   */
  paddingBoxHorizontal?: number;
  /**
   * Remove detected boxes with area below this threshold, in pixels.
   * @default 20
   */
  minimumAreaThreshold?: number;
  textPixelThreshold?: number;
  /**
   * Kernel size used in detection dilation post-processing.
   * @default 1
   */
  dilationKernelSize?: number;
}
/**
 * Parameters for the text detection service.
 */
interface DetectionServiceOptions extends DetectionRuntimeOptions {
  /**
   * ArrayBuffer containing the ONNX model for text detection.
   */
  modelBuffer?: ArrayBuffer;
}
/**
 * Runtime parameters for text recognition.
 */
interface RecognitionRuntimeOptions {
  /**
   * Fixed height for input images, in pixels.
   * Models will resize width proportionally.
   * @default 48
   */
  imageHeight?: number;
  /**
   * Per-channel mean values used to normalize input pixels [R, G, B].
   * @default [127.5, 127.5, 127.5]
   */
  mean?: [number, number, number];
  /**
   * Per-channel standard deviation values used to normalize input pixels [R, G, B].
   * @default [0.00784313725490196, 0.00784313725490196, 0.00784313725490196]
   */
  stdDeviation?: [number, number, number];
  /**
   * A list of loaded character dictionary (string) for
   * recognition result decoding.
   */
  charactersDictionary?: string[];
}
/**
 * Parameters for the text recognition service.
 */
interface RecognitionServiceOptions extends RecognitionRuntimeOptions {
  /**
   * ArrayBuffer containing the ONNX model for text recognition.
   */
  modelBuffer?: ArrayBuffer;
}
/**
 * Parameters for sorting detection boxes into reading order.
 */
interface RecognitionOrderingOptions {
  /**
   * Whether recognition results should be sorted in reading order.
   * @default true
   */
  sortByReadingOrder?: boolean;
  /**
   * Threshold ratio used to decide whether two boxes are on the same line.
   * The threshold is `(boxA.height + boxB.height) * sameLineThresholdRatio`.
   * @default 0.25
   */
  sameLineThresholdRatio?: number;
}
/**
 * Parameters for post-processing recognition results into lines.
 */
interface ProcessRecognitionOptions {
  /**
   * Threshold ratio used to merge results into the same line.
   * The threshold is `averageLineHeight * lineMergeThresholdRatio`.
   * @default 0.5
   */
  lineMergeThresholdRatio?: number;
}
interface OrtTensor {
  data: unknown;
  dims: readonly number[];
}
interface OrtInferenceSession {
  outputNames: readonly string[];
  run(feeds: Record<string, OrtTensor>): Promise<Record<string, OrtTensor>>;
  release?(): Promise<void>;
}
interface OrtTensorConstructor {
  new (type: string, data: Float32Array, dims: readonly number[]): OrtTensor;
}
interface OrtInferenceSessionConstructor {
  create(modelBuffer: ArrayBuffer): Promise<OrtInferenceSession>;
}
interface OrtModule {
  Tensor: OrtTensorConstructor;
  InferenceSession: OrtInferenceSessionConstructor;
}
/**
 * Full configuration for the PaddleOCR service.
 * Combines model file paths with detection, recognition, and debugging parameters.
 */
interface PaddleOptions {
  /**
   * onnxruntime module
   */
  ort?: OrtModule;
  /**
   * Controls parameters for text detection.
   */
  detection?: Partial<DetectionServiceOptions>;
  /**
   * Controls parameters for text recognition.
   */
  recognition?: Partial<RecognitionServiceOptions>;
}
/**
 * Options for each recognition task.
 */
interface RecognitionOptions {
  charWhiteList?: string[];
  onProgress?: (event: PaddleOcrProgressEvent) => void;
  detection?: Partial<DetectionRuntimeOptions>;
  recognition?: Partial<RecognitionRuntimeOptions>;
  ordering?: Partial<RecognitionOrderingOptions>;
}
interface OcrProgress {
  current: number;
  remain: number;
  total: number;
}
type PaddleOcrProgressEvent = {
  type: "det";
  stage: "preprocess" | "infer" | "postprocess";
  progress: OcrProgress;
  detectedCount?: number;
} | {
  type: "rec";
  stage: "start" | "item" | "complete";
  progress: OcrProgress;
  index?: number;
  box?: Box;
  result?: RecognitionResult;
};
/**
 * Simple rectangle representation.
 */
interface Box {
  /** X-coordinate of the top-left corner. */
  x: number;
  /** Y-coordinate of the top-left corner. */
  y: number;
  /** Width of the box in pixels. */
  width: number;
  /** Height of the box in pixels. */
  height: number;
}
//#endregion
//#region src/constants.d.ts
type DetectionDefaults = Required<DetectionRuntimeOptions>;
type RecognitionDefaults = Required<RecognitionRuntimeOptions>;
type RecognitionOrderingDefaults = Required<RecognitionOrderingOptions>;
type ProcessRecognitionDefaults = Required<ProcessRecognitionOptions>;
declare const DEFAULT_DETECTION_OPTIONS: DetectionDefaults;
declare const DEFAULT_RECOGNITION_OPTIONS: RecognitionDefaults;
declare const DEFAULT_RECOGNITION_ORDERING_OPTIONS: RecognitionOrderingDefaults;
declare const DEFAULT_PROCESS_RECOGNITION_OPTIONS: ProcessRecognitionDefaults;
declare const DEFAULT_PADDLE_OPTIONS: Partial<PaddleOptions>;
//#endregion
//#region src/processor/detection.d.ts
interface ResizeParams {
  srcWidth: number;
  srcHeight: number;
  dstWidth: number;
  dstHeight: number;
  scaleWidth: number;
  scaleHeight: number;
}
/**
 * Result of preprocessing an image for text detection
 */
interface PreprocessDetectionResult {
  tensor: Float32Array;
  resizeParams: ResizeParams;
}
interface DetectionRunOptions extends Partial<DetectionRuntimeOptions> {
  onProgress?: (event: PaddleOcrProgressEvent) => void;
}
/**
 * Service for detecting text regions in images
 */
declare class DetectionService {
  private static readonly TOTAL_PROGRESS_STEPS;
  private readonly options;
  private readonly session;
  private readonly ortModule;
  constructor(ortModule: OrtModule, session: OrtInferenceSession, options?: Partial<DetectionRuntimeOptions>);
  /**
   * Main method to run text detection on an image
   * @param image ArrayBuffer of the image or Canvas
   */
  run(image: Image, options?: DetectionRunOptions): Promise<Box[]>;
  private resolveRuntimeOptions;
  private createProgress;
  /**
   * Preprocess an image for text detection
   */
  private preprocessDetection;
  /**
   * Calculate dimensions for resizing the image
   */
  private calculateResizeDimensions;
  /**
   * Run the detection model inference
   */
  private runInference;
  /**
   * Process detection results to extract bounding boxes
   */
  private postprocessDetection;
  /**
   * Apply padding to a rectangle
   */
  private applyPaddingToRect;
  /**
   * Convert coordinates from resized image back to original image
   */
  private convertToOriginalCoordinates;
}
//#endregion
//#region src/processor/paddle-ocr.d.ts
interface PaddleOcrResult {
  text: string;
  lines: RecognitionResult[][];
  confidence: number;
}
interface FlattenedPaddleOcrResult {
  text: string;
  results: RecognitionResult[];
  confidence: number;
}
/**
 * PaddleOcrService - Provides OCR functionality using PaddleOCR models
 *
 * This service can be used either as a singleton or as separate instances
 * depending on your application needs.
 */
declare class PaddleOcrService {
  options: PaddleOptions;
  detectionSession: OrtInferenceSession | null;
  detectionService: DetectionService | null;
  recognitionSession: OrtInferenceSession | null;
  recognitionService: RecognitionService | null;
  /**
   * Create a new PaddleOcrService instance
   * @param options Optional configuration options
   */
  constructor(options?: Partial<PaddleOptions>);
  /**
   * Initialize the OCR service by loading models
   */
  initialize(): Promise<void>;
  /**
   * Check if the service is initialized with models loaded
   */
  isInitialized(): boolean;
  /**
   * Create a new instance instead of using the singleton
   * This is useful when you need multiple instances with different models
   * @param options Configuration options for this specific instance
   */
  static createInstance(options?: PaddleOptions): Promise<PaddleOcrService>;
  private resolveDetectionRuntimeOptions;
  private resolveRecognitionRuntimeOptions;
  private resolveRecognitionOrderingOptions;
  /**
   * Runs object detection on the provided image input, then performs
   * recognition on the detected regions.
   *
   * @param image - The raw image data as an ArrayBuffer or Canvas.
   * @param options - Optional configuration for the recognition output, e.g., `{ flatten: true }`.
   * @return A promise that resolves to the OCR result, either grouped by lines or as a flat list.
   */
  recognize(input: ImageInput, options?: RecognitionOptions): Promise<RecognitionResult[]>;
  /**
   * Processes raw recognition results to generate the final text,
   * grouped lines, and overall confidence.
   */
  processRecognition(recognition: RecognitionResult[], options?: ProcessRecognitionOptions): PaddleOcrResult;
  /**
   * Releases the onnx runtime session for both
   * detection and recognition model.
   */
  destroy(): Promise<void>;
}
//#endregion
export { type Box, DEFAULT_DETECTION_OPTIONS, DEFAULT_PADDLE_OPTIONS, DEFAULT_PROCESS_RECOGNITION_OPTIONS, DEFAULT_RECOGNITION_OPTIONS, DEFAULT_RECOGNITION_ORDERING_OPTIONS, type DetectionRuntimeOptions, DetectionService, type DetectionServiceOptions, type FlattenedPaddleOcrResult, type OcrProgress, type OrtInferenceSession, type OrtModule, type OrtTensor, type PaddleOcrProgressEvent, type PaddleOcrResult, PaddleOcrService, type PaddleOptions, type PreprocessDetectionResult, type ProcessRecognitionOptions, type RecognitionOptions, type RecognitionOrderingOptions, type RecognitionResult, type RecognitionRuntimeOptions, RecognitionService, type RecognitionServiceOptions };
//# sourceMappingURL=index.d.cts.map