{"version":3,"file":"types.cjs","names":[],"sources":["../../src/vision/types.ts"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Public output types returned by the SDK's vision tasks.\n *\n * These types form the contract between the SDK and its callers. They mirror\n * the Python `ort-vision-sdk` output dataclasses 1-to-1.\n *\n * Naming is intentionally compatible with the Ultralytics / torchvision idiom\n * (`cls`, `conf`, `box`, `xyxy`, `xywh`, normalized variants) so code ported\n * from those projects keeps working with minimal edits. The original verbose\n * names (`classId`, `className`, `confidence`, `bbox`) are still populated for\n * backwards compatibility.\n */\n\nimport { ImageLoadError } from \"./core/exceptions\";\n\n/**\n * HWC RGB uint8 image — the canonical image format used across the SDK.\n *\n * `data.length` must equal `width * height * 3`. The buffer is laid out row\n * by row, top-to-bottom, with each pixel as `[R, G, B]`.\n */\nexport class RGBImage {\n    constructor(\n        public readonly data: Uint8Array,\n        public readonly width: number,\n        public readonly height: number,\n    ) {\n        if (data.length !== width * height * 3) {\n            throw new ImageLoadError(\n                `RGBImage data length ${data.length} does not match width * height * 3 = ${\n                    width * height * 3\n                }.`,\n            );\n        }\n    }\n}\n\n/**\n * Axis-aligned bounding box in absolute pixel coordinates (xyxy format).\n *\n * Coordinates refer to the original input image (before any internal resize),\n * so callers can map detections back onto their source image without any\n * additional bookkeeping.\n */\nexport class BoundingBox {\n    constructor(\n        public readonly x1: number,\n        public readonly y1: number,\n        public readonly x2: number,\n        public readonly y2: number,\n    ) {}\n\n    /** Box width in pixels (clamped to non-negative). */\n    get width(): number {\n        return Math.max(0, this.x2 - this.x1);\n    }\n\n    /** Box height in pixels (clamped to non-negative). */\n    get height(): number {\n        return Math.max(0, this.y2 - this.y1);\n    }\n\n    /** Box area in pixels squared. */\n    get area(): number {\n        return this.width * this.height;\n    }\n\n    /** The box as `[x1, y1, x2, y2]` in absolute pixels (Ultralytics-style). */\n    get xyxy(): readonly [number, number, number, number] {\n        return [this.x1, this.y1, this.x2, this.y2];\n    }\n\n    /**\n     * The box as `[cx, cy, w, h]` with `(cx, cy)` at the center.\n     *\n     * Matches Ultralytics' `boxes.xywh` and YOLO's native head format. For the\n     * top-left `[x, y, w, h]` convention, use {@link asXywh}.\n     */\n    get xywh(): readonly [number, number, number, number] {\n        return [(this.x1 + this.x2) / 2, (this.y1 + this.y2) / 2, this.width, this.height];\n    }\n\n    /**\n     * The box as `[x1, y1, x2, y2]` normalized to `[0, 1]`.\n     *\n     * @param origShape `[height, width]` of the source image, in pixels.\n     */\n    xyxyn(origShape: readonly [number, number]): readonly [number, number, number, number] {\n        const [h, w] = origShape;\n        if (w <= 0 || h <= 0) return [0, 0, 0, 0];\n        return [this.x1 / w, this.y1 / h, this.x2 / w, this.y2 / h];\n    }\n\n    /**\n     * The box as `[cx, cy, w, h]` normalized to `[0, 1]`.\n     *\n     * @param origShape `[height, width]` of the source image, in pixels.\n     */\n    xywhn(origShape: readonly [number, number]): readonly [number, number, number, number] {\n        const [h, w] = origShape;\n        if (w <= 0 || h <= 0) return [0, 0, 0, 0];\n        const [cx, cy, bw, bh] = this.xywh;\n        return [cx / w, cy / h, bw / w, bh / h];\n    }\n\n    /** Returns `[x1, y1, x2, y2]`. */\n    asXyxy(): readonly [number, number, number, number] {\n        return [this.x1, this.y1, this.x2, this.y2];\n    }\n\n    /**\n     * Returns `[x, y, width, height]` with `(x, y)` at the **top-left**.\n     *\n     * Note: this is the top-left convention. Ultralytics' `xywh` getter uses\n     * **center** coordinates — for that, read {@link xywh}.\n     */\n    asXywh(): readonly [number, number, number, number] {\n        return [this.x1, this.y1, this.width, this.height];\n    }\n\n    /** Returns `[x1, y1, x2, y2]` truncated to integers, useful for slicing arrays. */\n    asIntXyxy(): readonly [number, number, number, number] {\n        return [Math.trunc(this.x1), Math.trunc(this.y1), Math.trunc(this.x2), Math.trunc(this.y2)];\n    }\n}\n\n/**\n * Probability assigned to a single class for a classification prediction.\n *\n * `cls` / `name` / `conf` are Ultralytics-style aliases populated alongside\n * the verbose `classId` / `className` / `probability` fields.\n */\nexport interface ClassProbability {\n    readonly classId: number;\n    readonly className: string;\n    readonly probability: number;\n    /** Alias for `classId` (Ultralytics-style). */\n    readonly cls: number;\n    /** Alias for `className`. */\n    readonly name: string;\n    /** Alias for `probability` (Ultralytics-style). */\n    readonly conf: number;\n}\n\n/**\n * Output of an image classification inference.\n */\nexport interface ClassificationResult {\n    readonly classId: number;\n    readonly className: string;\n    readonly confidence: number;\n    /** Alias for `classId` (Ultralytics-style). */\n    readonly cls: number;\n    /** Alias for `className`. */\n    readonly name: string;\n    /** Alias for `confidence` (Ultralytics-style). */\n    readonly conf: number;\n    /** The original input image as an HWC RGB uint8 array. */\n    readonly image: RGBImage;\n    /**\n     * Probabilities per class, sorted in descending order. The first entry\n     * mirrors `classId`, `className`, and `confidence`. When `topK` was passed\n     * to `predict`, the array is truncated to that length.\n     */\n    readonly probabilities: readonly ClassProbability[];\n}\n\n/**\n * Single detected object produced by an object-detection model.\n */\nexport interface DetectionResult {\n    readonly classId: number;\n    readonly className: string;\n    readonly confidence: number;\n    readonly bbox: BoundingBox;\n    /** Alias for `classId` (Ultralytics-style). */\n    readonly cls: number;\n    /** Alias for `className`. */\n    readonly name: string;\n    /** Alias for `confidence` (Ultralytics-style). */\n    readonly conf: number;\n    /** Alias for `bbox` (Ultralytics-style). */\n    readonly box: BoundingBox;\n    /**\n     * The original image cropped to `bbox`, HWC RGB uint8. Empty boxes\n     * (zero area) yield a zero-sized `RGBImage`.\n     */\n    readonly croppedImage: RGBImage;\n    /**\n     * What a second, classification stage predicted **for this crop** —\n     * populated only by {@link DetectClassify}, and `null` for a plain detector.\n     *\n     * Kept as its own field rather than folded into `classId`/`className`\n     * because the two answers are different questions: the detector says *what\n     * kind of object this is*, the classifier says *which sub-category the object\n     * belongs to*, and collapsing them would lose one of the two.\n     */\n    readonly classification?: ClassificationResult | null;\n}\n\n/**\n * Single-channel binary or grayscale mask, laid out row-major.\n *\n * `data.length` must equal `width * height`. For binary masks, values are\n * `0` (background) or `255` (foreground); soft masks may use the full\n * `[0, 255]` range.\n */\nexport class Mask {\n    constructor(\n        public readonly data: Uint8Array,\n        public readonly width: number,\n        public readonly height: number,\n    ) {\n        if (data.length !== width * height) {\n            throw new ImageLoadError(\n                `Mask data length ${data.length} does not match width * height = ${\n                    width * height\n                }.`,\n            );\n        }\n    }\n}\n\n/**\n * Single segmented instance produced by an instance-segmentation model.\n *\n * Mirrors {@link DetectionResult} and adds the per-instance binary mask\n * plus a \"ready-to-display\" background-removed crop.\n */\nexport interface SegmentationResult {\n    readonly classId: number;\n    readonly className: string;\n    readonly confidence: number;\n    readonly bbox: BoundingBox;\n    /** Alias for `classId` (Ultralytics-style). */\n    readonly cls: number;\n    /** Alias for `className`. */\n    readonly name: string;\n    /** Alias for `confidence` (Ultralytics-style). */\n    readonly conf: number;\n    /** Alias for `bbox` (Ultralytics-style). */\n    readonly box: BoundingBox;\n    /**\n     * Binary mask cropped to `bbox`. Values are `0` (background) or `255`\n     * (foreground). Empty boxes yield a zero-sized `Mask`.\n     */\n    readonly mask: Mask;\n    /**\n     * The original image cropped to `bbox` with background pixels (where\n     * `mask.data[i] === 0`) zeroed out. Empty boxes yield a zero-sized\n     * `RGBImage`.\n     */\n    readonly segmentedImage: RGBImage;\n}\n"],"mappings":"yCAsBA,IAAa,EAAb,KAAsB,CAEE,KACA,MACA,OAHpB,YACI,EACA,EACA,EACF,CACE,GAJgB,KAAA,KAAA,EACA,KAAA,MAAA,EACA,KAAA,OAAA,EAEZ,EAAK,SAAW,EAAQ,EAAS,EACjC,MAAM,IAAI,EAAA,eACN,wBAAwB,EAAK,OAAO,uCAChC,EAAQ,EAAS,EACpB,EACL,CAER,CACJ,EASa,EAAb,KAAyB,CAED,GACA,GACA,GACA,GAJpB,YACI,EACA,EACA,EACA,EACF,CAJkB,KAAA,GAAA,EACA,KAAA,GAAA,EACA,KAAA,GAAA,EACA,KAAA,GAAA,CACjB,CAGH,IAAI,OAA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