import type { InferenceSession, Tensor } from "onnxruntime-common"; import type { Canvas, Contours, ImageProcessor, cv } from "ppu-ocv"; import type { CanvasLike } from "ppu-ocv/web"; export type CoreCanvas = Canvas | CanvasLike; /** * Optional wrapper for platform-specific OpenCV image manipulation. * * Only populated when `processing.engine === "opencv"` (Node/Bun). * Web builds leave this `undefined` and always use canvas-native processing. */ export interface ImageProcessorProvider { /** Injects the source image buffer into a universally parsable Canvas */ prepareCanvas: (image: unknown) => Promise; /** Wrapper class handling matrix transformations */ ImageProcessor: new (canvas: TCanvas) => ImageProcessor; /** Wrapper class handling mathematical OpenCV contours */ Contours: new (mat: cv.Mat, options: { mode: number; method: number; }) => Contours; /** Raw OpenCV WebAssembly object reference */ cv: typeof cv; } /** * A generic abstraction mapping specifically to pure runtime-level APIs * (like ort/onnxruntime, canvas APIs, fetching mechanisms, etc). * * This injects the platform-specific dependencies into the shared Core logic. */ export interface PlatformProvider { /** The specific pathing delimiter used on this platform (ie '/' vs '\') */ pathSeparator: string; /** Platform-specific ONNX Runtime namespace (`onnxruntime-node` vs `onnxruntime-web`) */ ort: { Tensor: typeof Tensor; InferenceSession: typeof InferenceSession; }; /** Platform-specific canvas constructor (`createCanvas` vs `getPlatform().createCanvas`) */ createCanvas: (width: number, height: number) => TCanvas; /** Type guard determining if an object is a recognized Canvas API implementation */ isCanvas: (image: unknown) => image is TCanvas; /** Resolves resources asynchronously via local FileSystem (`fs`) or HTTP (`fetch`) based on the environment */ loadResource: (source: string | ArrayBuffer | undefined, defaultUrl: string) => Promise; /** Optionally dump a given Canvas representation directly onto the disk (No-Op on Web context) */ saveDebugImage: (canvas: TCanvas, filename: string, path: string) => Promise; /** OpenCV-based image processor (only available in Node/Bun environments) */ imageProcessor?: ImageProcessorProvider; }