@depz/camera-sdk 0.0.0-stage → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ export { DepzError, ErrorCode, errorCodeMeaning, errorCodeName, errorCodeOf } from "./errors";
2
+ export { configure, currentSettings, getCacheDir, Settings, CORRECTION_TERMS, LOG_LEVELS, RECALIBRATION_MODES, type CorrectionTerm, type LogHandler, type RecalibrationMode, type SettingsOptions, } from "./settings";
3
+ export { Calibration, cameraModelOfPid, cameraModelOfSerial, cameraModelOfSku, InferenceRoi, type BgrImage, type CameraModel, type CanvasLayout, type CanvasOptions, type Control, type ControlType, type EnumMember, type Eye, } from "./calibration";
4
+ export { FramePacket, ImageView, RawFrame, type FrameTiming, type ImageKind, type Intrinsics, type PixelFormat } from "./frames";
5
+ export { CameraSource, FrameSource, MkvSource, type CameraSourceOptions, type MkvSourceOptions, type ReplayMode, type SourceInfo } from "./sources";
6
+ export { CameraInfo, cameraFamilyControls, cameraFamilyModes, findCamera, listCameras, scanCameras, type AttachedCamera, type CalibrationSource, type CameraStatus, type CaptureMode, type ScanOptions, } from "./cameras";
7
+ export { buildInference, clearEngineCaches, defaultModel, DepthStage, describeEngines, downloadModel, engineCacheStatus, Inference, inputSizeSupport, isModelCached, listModels, modelFiles, modelSupport, parseEngineSlug, type BuildOptions, type DepthStageOptions, type EngineCacheStatus, type EngineInfo, type InferenceInfo, type InputSize, type InputSizeKind, type ModelInfo, type ModelSupport, type ModelVariantInfo, type RegionLimits, } from "./inference";
8
+ export { ControlSet, Pipeline, PipelineConfig, RecalibrationConfig, Recording, Replay, STREAMS, type ErrorInfo, type RecordingResult, type RecordingStatus, type OutputDropPolicy, type PipelineConfigOptions, type PipelineInfo, type RecalibrationConfigOptions, type RecalibrationProfile, type Stream, } from "./pipeline";
9
+ /** The native library's version (semver). */
10
+ export declare function nativeVersion(): string;
11
+ /** The host clock frame timing is on, ns. */
12
+ export declare function hostClockNs(): bigint;
package/dist/index.js ADDED
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.STREAMS = exports.Replay = exports.Recording = exports.RecalibrationConfig = exports.PipelineConfig = exports.Pipeline = exports.ControlSet = exports.parseEngineSlug = exports.modelSupport = exports.modelFiles = exports.listModels = exports.isModelCached = exports.inputSizeSupport = exports.Inference = exports.engineCacheStatus = exports.downloadModel = exports.describeEngines = exports.DepthStage = exports.defaultModel = exports.clearEngineCaches = exports.buildInference = exports.scanCameras = exports.listCameras = exports.findCamera = exports.cameraFamilyModes = exports.cameraFamilyControls = exports.CameraInfo = exports.MkvSource = exports.FrameSource = exports.CameraSource = exports.RawFrame = exports.ImageView = exports.FramePacket = exports.InferenceRoi = exports.cameraModelOfSku = exports.cameraModelOfSerial = exports.cameraModelOfPid = exports.Calibration = exports.RECALIBRATION_MODES = exports.LOG_LEVELS = exports.CORRECTION_TERMS = exports.Settings = exports.getCacheDir = exports.currentSettings = exports.configure = exports.errorCodeOf = exports.errorCodeName = exports.errorCodeMeaning = exports.ErrorCode = exports.DepzError = void 0;
4
+ exports.nativeVersion = nativeVersion;
5
+ exports.hostClockNs = hostClockNs;
6
+ // SPDX-License-Identifier: Apache-2.0
7
+ // @depz/camera-sdk: the DEPZ camera SDK for Node.js, over the native SDK's C ABI.
8
+ //
9
+ // Names: the reference's (Python depz_camera_sdk), in TypeScript's conventions - classes and
10
+ // types PascalCase as there; functions, methods, properties and options lowerCamelCase
11
+ // (from_json -> fromJson, baseline_m -> baselineM, the unit suffix kept); the values of the
12
+ // reference's string enums as string literal types ("every_frame", "rectified_left");
13
+ // ErrorCode's members PascalCase (ErrorCode.CameraBusy; errorCodeName gives "camera_busy").
14
+ // A blocking call (open, grab, get, start, stop, buildInference) returns a Promise.
15
+ const native_1 = require("./native");
16
+ var errors_1 = require("./errors");
17
+ Object.defineProperty(exports, "DepzError", { enumerable: true, get: function () { return errors_1.DepzError; } });
18
+ Object.defineProperty(exports, "ErrorCode", { enumerable: true, get: function () { return errors_1.ErrorCode; } });
19
+ Object.defineProperty(exports, "errorCodeMeaning", { enumerable: true, get: function () { return errors_1.errorCodeMeaning; } });
20
+ Object.defineProperty(exports, "errorCodeName", { enumerable: true, get: function () { return errors_1.errorCodeName; } });
21
+ Object.defineProperty(exports, "errorCodeOf", { enumerable: true, get: function () { return errors_1.errorCodeOf; } });
22
+ var settings_1 = require("./settings");
23
+ Object.defineProperty(exports, "configure", { enumerable: true, get: function () { return settings_1.configure; } });
24
+ Object.defineProperty(exports, "currentSettings", { enumerable: true, get: function () { return settings_1.currentSettings; } });
25
+ Object.defineProperty(exports, "getCacheDir", { enumerable: true, get: function () { return settings_1.getCacheDir; } });
26
+ Object.defineProperty(exports, "Settings", { enumerable: true, get: function () { return settings_1.Settings; } });
27
+ Object.defineProperty(exports, "CORRECTION_TERMS", { enumerable: true, get: function () { return settings_1.CORRECTION_TERMS; } });
28
+ Object.defineProperty(exports, "LOG_LEVELS", { enumerable: true, get: function () { return settings_1.LOG_LEVELS; } });
29
+ Object.defineProperty(exports, "RECALIBRATION_MODES", { enumerable: true, get: function () { return settings_1.RECALIBRATION_MODES; } });
30
+ var calibration_1 = require("./calibration");
31
+ Object.defineProperty(exports, "Calibration", { enumerable: true, get: function () { return calibration_1.Calibration; } });
32
+ Object.defineProperty(exports, "cameraModelOfPid", { enumerable: true, get: function () { return calibration_1.cameraModelOfPid; } });
33
+ Object.defineProperty(exports, "cameraModelOfSerial", { enumerable: true, get: function () { return calibration_1.cameraModelOfSerial; } });
34
+ Object.defineProperty(exports, "cameraModelOfSku", { enumerable: true, get: function () { return calibration_1.cameraModelOfSku; } });
35
+ Object.defineProperty(exports, "InferenceRoi", { enumerable: true, get: function () { return calibration_1.InferenceRoi; } });
36
+ var frames_1 = require("./frames");
37
+ Object.defineProperty(exports, "FramePacket", { enumerable: true, get: function () { return frames_1.FramePacket; } });
38
+ Object.defineProperty(exports, "ImageView", { enumerable: true, get: function () { return frames_1.ImageView; } });
39
+ Object.defineProperty(exports, "RawFrame", { enumerable: true, get: function () { return frames_1.RawFrame; } });
40
+ var sources_1 = require("./sources");
41
+ Object.defineProperty(exports, "CameraSource", { enumerable: true, get: function () { return sources_1.CameraSource; } });
42
+ Object.defineProperty(exports, "FrameSource", { enumerable: true, get: function () { return sources_1.FrameSource; } });
43
+ Object.defineProperty(exports, "MkvSource", { enumerable: true, get: function () { return sources_1.MkvSource; } });
44
+ var cameras_1 = require("./cameras");
45
+ Object.defineProperty(exports, "CameraInfo", { enumerable: true, get: function () { return cameras_1.CameraInfo; } });
46
+ Object.defineProperty(exports, "cameraFamilyControls", { enumerable: true, get: function () { return cameras_1.cameraFamilyControls; } });
47
+ Object.defineProperty(exports, "cameraFamilyModes", { enumerable: true, get: function () { return cameras_1.cameraFamilyModes; } });
48
+ Object.defineProperty(exports, "findCamera", { enumerable: true, get: function () { return cameras_1.findCamera; } });
49
+ Object.defineProperty(exports, "listCameras", { enumerable: true, get: function () { return cameras_1.listCameras; } });
50
+ Object.defineProperty(exports, "scanCameras", { enumerable: true, get: function () { return cameras_1.scanCameras; } });
51
+ var inference_1 = require("./inference");
52
+ Object.defineProperty(exports, "buildInference", { enumerable: true, get: function () { return inference_1.buildInference; } });
53
+ Object.defineProperty(exports, "clearEngineCaches", { enumerable: true, get: function () { return inference_1.clearEngineCaches; } });
54
+ Object.defineProperty(exports, "defaultModel", { enumerable: true, get: function () { return inference_1.defaultModel; } });
55
+ Object.defineProperty(exports, "DepthStage", { enumerable: true, get: function () { return inference_1.DepthStage; } });
56
+ Object.defineProperty(exports, "describeEngines", { enumerable: true, get: function () { return inference_1.describeEngines; } });
57
+ Object.defineProperty(exports, "downloadModel", { enumerable: true, get: function () { return inference_1.downloadModel; } });
58
+ Object.defineProperty(exports, "engineCacheStatus", { enumerable: true, get: function () { return inference_1.engineCacheStatus; } });
59
+ Object.defineProperty(exports, "Inference", { enumerable: true, get: function () { return inference_1.Inference; } });
60
+ Object.defineProperty(exports, "inputSizeSupport", { enumerable: true, get: function () { return inference_1.inputSizeSupport; } });
61
+ Object.defineProperty(exports, "isModelCached", { enumerable: true, get: function () { return inference_1.isModelCached; } });
62
+ Object.defineProperty(exports, "listModels", { enumerable: true, get: function () { return inference_1.listModels; } });
63
+ Object.defineProperty(exports, "modelFiles", { enumerable: true, get: function () { return inference_1.modelFiles; } });
64
+ Object.defineProperty(exports, "modelSupport", { enumerable: true, get: function () { return inference_1.modelSupport; } });
65
+ Object.defineProperty(exports, "parseEngineSlug", { enumerable: true, get: function () { return inference_1.parseEngineSlug; } });
66
+ var pipeline_1 = require("./pipeline");
67
+ Object.defineProperty(exports, "ControlSet", { enumerable: true, get: function () { return pipeline_1.ControlSet; } });
68
+ Object.defineProperty(exports, "Pipeline", { enumerable: true, get: function () { return pipeline_1.Pipeline; } });
69
+ Object.defineProperty(exports, "PipelineConfig", { enumerable: true, get: function () { return pipeline_1.PipelineConfig; } });
70
+ Object.defineProperty(exports, "RecalibrationConfig", { enumerable: true, get: function () { return pipeline_1.RecalibrationConfig; } });
71
+ Object.defineProperty(exports, "Recording", { enumerable: true, get: function () { return pipeline_1.Recording; } });
72
+ Object.defineProperty(exports, "Replay", { enumerable: true, get: function () { return pipeline_1.Replay; } });
73
+ Object.defineProperty(exports, "STREAMS", { enumerable: true, get: function () { return pipeline_1.STREAMS; } });
74
+ /** The native library's version (semver). */
75
+ function nativeVersion() {
76
+ return native_1.native.depz_version();
77
+ }
78
+ /** The host clock frame timing is on, ns. */
79
+ function hostClockNs() {
80
+ return native_1.native.depz_host_clock_ns();
81
+ }
@@ -0,0 +1,175 @@
1
+ import { InferenceRoi, type Eye } from "./calibration";
2
+ import { type NativeFlag, type NativeHandle } from "./native";
3
+ /** [height, width] of a model input. */
4
+ export type InputSize = readonly [number, number];
5
+ /** One variant of a model family: its input size. */
6
+ export interface ModelVariantInfo {
7
+ readonly slug: string;
8
+ readonly label: string;
9
+ /** [height, width]; null: any size (a classical matcher). */
10
+ readonly inputSize: InputSize | null;
11
+ /** Typical disparity error at this size, input px; null: not measured. */
12
+ readonly disparityErrorPx: number | null;
13
+ }
14
+ /** One model family of the catalog (contracts/models.json). */
15
+ export interface ModelInfo {
16
+ readonly slug: string;
17
+ readonly label: string;
18
+ readonly neural: boolean;
19
+ readonly mono: boolean;
20
+ readonly outputsDepth: boolean;
21
+ readonly variants: readonly ModelVariantInfo[];
22
+ /** The largest disparity it outputs, input px; null: no fixed ceiling or not known. */
23
+ readonly maxDisparityPx: number | null;
24
+ readonly disparityOffsetVerified: boolean;
25
+ readonly consistencyCheck: boolean;
26
+ readonly licence: string | null;
27
+ readonly licenceUrl: string | null;
28
+ readonly defaultFor: "stereo" | "mono" | null;
29
+ readonly defaultVariant: string | null;
30
+ }
31
+ /** The model catalog (contracts/models.json). */
32
+ export declare function listModels(): ModelInfo[];
33
+ /** One engine the SDK knows and whether this host runs it. */
34
+ export interface EngineInfo {
35
+ readonly slug: string;
36
+ readonly kind: string;
37
+ readonly device: string;
38
+ readonly available: boolean;
39
+ readonly unavailableReason: string;
40
+ readonly precisions: readonly string[];
41
+ readonly explicitOnly: boolean;
42
+ readonly options: readonly string[];
43
+ readonly installed: boolean;
44
+ /** null: not probed yet. */
45
+ readonly usable: boolean | null;
46
+ /** null when none. */
47
+ readonly runtimeVersion: string | null;
48
+ readonly untested: boolean;
49
+ readonly hidden: boolean;
50
+ readonly engineClass: "unknown" | "cpu" | "igpu" | "nvidia";
51
+ }
52
+ /** Every engine the SDK knows and whether this host runs it. */
53
+ export declare function describeEngines(): EngineInfo[];
54
+ /** "any": any size of the engine's multiple; "listed": only the sizes given. */
55
+ export type InputSizeKind = "any" | "listed";
56
+ /** The limits of a region and of a model input, in pixels at the model's density. */
57
+ export interface RegionLimits {
58
+ readonly minWidth: number;
59
+ readonly minHeight: number;
60
+ readonly goodWidth: number;
61
+ readonly goodHeight: number;
62
+ readonly inputMultiple: number;
63
+ readonly leftMarginMaxPx: number;
64
+ readonly leftMarginShare: number;
65
+ }
66
+ /** Whether an engine may run a model at a size (the reference's ModelSupport). */
67
+ export interface ModelSupport {
68
+ readonly ok: boolean;
69
+ /** null when ok, else an engines.json model_support code. */
70
+ readonly code: string | null;
71
+ /** "" when ok, else the sentence for people. */
72
+ readonly reason: string;
73
+ /** The precision the engine computes it in; null: the engine's own default. */
74
+ readonly precision: string | null;
75
+ readonly verified: boolean;
76
+ readonly regionKind: InputSizeKind;
77
+ /** [height, width] pairs, smallest first. */
78
+ readonly regionSizes: readonly InputSize[];
79
+ readonly regionLimits: RegionLimits;
80
+ /** The smallest input the engine runs the model at, [height, width]; null: no such floor. */
81
+ readonly minInput: InputSize | null;
82
+ }
83
+ /** Whether `engine` may run `family` (`variant`) at `inputSize` ([h, w]; omitted: the variant's own).
84
+ * engine null or "": no engine part (the family's rule). Pure: no download. */
85
+ export declare function modelSupport(family: string, variant: string | null, engine: string | null, inputSize?: InputSize | null): ModelSupport;
86
+ /** Which input sizes a model accepts on an engine: [kind, [[h, w], ...]] (input_size_support). */
87
+ export declare function inputSizeSupport(family: string, engine?: string | null): [InputSizeKind, InputSize[]];
88
+ /** An engine slug's two parts: [kind (lowercased), device_or_ep] ("openvino-GPU.0": ["openvino", "GPU.0"]). */
89
+ export declare function parseEngineSlug(slug: string): [string, string];
90
+ /** The model to run on engine when nobody chooses one, on this host: [family, variant], or null. */
91
+ export declare function defaultModel(engine: string | null): [string, string] | null;
92
+ /** The files a download of the model fetches (and buildInference runs), absolute under the cache root,
93
+ * the entry point first ([] for a classical matcher). Downloads nothing. */
94
+ export declare function modelFiles(family: string, variant: string, engine?: string | null, inputSize?: InputSize | null): string[];
95
+ /** What the engine caches hold for one model variant. */
96
+ export interface EngineCacheStatus {
97
+ readonly tensorrtPlans: number;
98
+ readonly tensorrtBytes: number;
99
+ /** The optimization level the newest plan was built with; null: no plan. */
100
+ readonly tensorrtOptLevel: number | null;
101
+ }
102
+ /** What the engine caches hold for one model variant. */
103
+ export declare function engineCacheStatus(family: string, variant: string): EngineCacheStatus;
104
+ /** Deletes engine caches (downloaded models are kept); what was deleted. kinds: null for all. */
105
+ export declare function clearEngineCaches(kinds: readonly string[] | null, options?: {
106
+ family?: string | null;
107
+ variant?: string | null;
108
+ }): string[];
109
+ /** The options of buildInference and downloadModel. */
110
+ export interface BuildOptions {
111
+ /** Exactly this engine, or a refusal; omitted: the first of this host's that may run it. */
112
+ engine?: string | null;
113
+ /** [height, width]; omitted: the variant's own. */
114
+ inputSize?: InputSize | null;
115
+ /** Reports ("download" bytes, "prepare"), on the main thread; never waited for. */
116
+ progress?: (stage: string, done: number, total: number) => void;
117
+ /** Cancels the build: it rejects with aborted. */
118
+ signal?: AbortSignal;
119
+ }
120
+ /** The native cancel flag of an AbortSignal. Internal. */
121
+ export declare function flagOf(signal: AbortSignal | undefined): NativeFlag | null;
122
+ /** What an inference runs. */
123
+ export interface InferenceInfo {
124
+ readonly model: string;
125
+ readonly variant: string;
126
+ readonly engine: string;
127
+ /** [height, width]; null: any size. */
128
+ readonly inputSize: InputSize | null;
129
+ readonly mono: boolean;
130
+ readonly outputsDepth: boolean;
131
+ readonly maxConcurrentRuns: number;
132
+ }
133
+ /** A model loaded on an engine (buildInference). */
134
+ export declare class Inference {
135
+ /** @internal */
136
+ readonly _h: NativeHandle;
137
+ /** @internal */
138
+ constructor(handle: NativeHandle);
139
+ get info(): InferenceInfo;
140
+ /** Sets one of the model's own controls (a catalog model's: SGBM's block_size, a monocular
141
+ * model's depth_scale, ...), coerced as in a pipeline's "inference" scope. */
142
+ controlSet(name: string, value: number | string | boolean): void;
143
+ /** Releases the model now (a depth stage that runs it keeps its own reference). */
144
+ release(): void;
145
+ }
146
+ /** Downloads (and checks) the files of a model for an engine and size into the cache; the paths. */
147
+ export declare function downloadModel(family: string, variant: string, options?: BuildOptions): Promise<string[]>;
148
+ /** Whether the files buildInference would use are in the cache. */
149
+ export declare function isModelCached(family: string, variant: string, options?: {
150
+ engine?: string | null;
151
+ inputSize?: InputSize | null;
152
+ }): boolean;
153
+ /** Loads `family` `variant` on an engine (downloads the files on first use, builds the engine). */
154
+ export declare function buildInference(family: string, variant: string, options?: BuildOptions): Promise<Inference>;
155
+ /** The depth stage's region, disparity offset and mono eye. */
156
+ export interface DepthStageOptions {
157
+ /** The region of the frame the model runs on; null: the whole frame. */
158
+ region?: InferenceRoi | null;
159
+ /** The right eye shifted this far before matching (added back after), px >= 0. */
160
+ disparityOffsetPx?: number;
161
+ /** The eye a mono model sees; omitted: left (a recording: the eye it recorded). */
162
+ monoEye?: Eye | null;
163
+ }
164
+ /** The depth stage: a model run on every frame of a pipeline (adds disparity, depth, the cloud). */
165
+ export declare class DepthStage {
166
+ readonly model: Inference;
167
+ readonly region: InferenceRoi | null;
168
+ readonly disparityOffsetPx: number;
169
+ readonly monoEye: Eye | null;
170
+ /** @internal */
171
+ readonly _h: NativeHandle;
172
+ /** The stage that runs `model` on every frame of a pipeline. */
173
+ constructor(model: Inference, options?: DepthStageOptions);
174
+ get name(): string;
175
+ }
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DepthStage = exports.Inference = void 0;
4
+ exports.listModels = listModels;
5
+ exports.describeEngines = describeEngines;
6
+ exports.modelSupport = modelSupport;
7
+ exports.inputSizeSupport = inputSizeSupport;
8
+ exports.parseEngineSlug = parseEngineSlug;
9
+ exports.defaultModel = defaultModel;
10
+ exports.modelFiles = modelFiles;
11
+ exports.engineCacheStatus = engineCacheStatus;
12
+ exports.clearEngineCaches = clearEngineCaches;
13
+ exports.flagOf = flagOf;
14
+ exports.downloadModel = downloadModel;
15
+ exports.isModelCached = isModelCached;
16
+ exports.buildInference = buildInference;
17
+ // SPDX-License-Identifier: Apache-2.0
18
+ // Models and engines (the reference's depz_camera_sdk_inference): the catalog, the engines of this
19
+ // host, model support, the input sizes, the engine slug's parts, the files of a download, the
20
+ // engines' caches, the default model; a model loaded on an engine (buildInference: a Promise, it
21
+ // may download and build); the depth stage (depz_camera_sdk_depth's DepthStage).
22
+ const C = require("./generated/constants.g");
23
+ const errors_1 = require("./errors");
24
+ const calibration_1 = require("./calibration");
25
+ const native_1 = require("./native");
26
+ const settings_1 = require("./settings");
27
+ const str = (v, what) => {
28
+ if (v === undefined || v === null)
29
+ return null;
30
+ if (typeof v !== "string")
31
+ throw (0, errors_1.invalidArgument)(`${what} must be a string or null`);
32
+ return v;
33
+ };
34
+ function sizeArgs(inputSize) {
35
+ if (inputSize === undefined || inputSize === null)
36
+ return [0, 0];
37
+ if (!Array.isArray(inputSize) || inputSize.length !== 2)
38
+ throw (0, errors_1.invalidArgument)("input_size must be (height, width)");
39
+ return [inputSize[1], inputSize[0]];
40
+ }
41
+ function pairs(flat, count) {
42
+ const out = [];
43
+ for (let i = 0; i < count; i++)
44
+ out.push([flat[2 * i], flat[2 * i + 1]]);
45
+ return out;
46
+ }
47
+ /** The model catalog (contracts/models.json). */
48
+ function listModels() {
49
+ return native_1.native.depz_list_models((0, settings_1.currentContext)()).map((m) => Object.freeze({
50
+ slug: m.slug, label: m.label, neural: m.neural !== 0, mono: m.mono !== 0, outputsDepth: m.outputsDepth !== 0,
51
+ variants: Object.freeze(m.variants.map((v) => Object.freeze({
52
+ slug: v.slug, label: v.label,
53
+ inputSize: v.inputWidth > 0 && v.inputHeight > 0 ? Object.freeze([v.inputHeight, v.inputWidth]) : null,
54
+ disparityErrorPx: v.disparityErrorPx > 0 ? v.disparityErrorPx : null,
55
+ }))),
56
+ maxDisparityPx: m.maxDisparityPx > 0 ? m.maxDisparityPx : null,
57
+ disparityOffsetVerified: m.disparityOffsetVerified !== 0, consistencyCheck: m.consistencyCheck !== 0,
58
+ licence: m.licence || null, licenceUrl: m.licenceUrl || null,
59
+ defaultFor: m.defaultFor === C.DEPZ_DEFAULT_FOR_STEREO ? "stereo" : m.defaultFor === C.DEPZ_DEFAULT_FOR_MONO ? "mono" : null,
60
+ defaultVariant: m.defaultVariant || null,
61
+ }));
62
+ }
63
+ const list = (s) => (s ? s.split(",") : []);
64
+ /** Every engine the SDK knows and whether this host runs it. */
65
+ function describeEngines() {
66
+ const classes = {
67
+ [C.DEPZ_ENGINE_CLASS_CPU]: "cpu", [C.DEPZ_ENGINE_CLASS_IGPU]: "igpu", [C.DEPZ_ENGINE_CLASS_NVIDIA]: "nvidia",
68
+ };
69
+ return native_1.native.depz_describe_engines((0, settings_1.currentContext)()).map((e) => Object.freeze({
70
+ slug: e.slug, kind: e.kind, device: e.device, available: e.available !== 0, unavailableReason: e.unavailableReason,
71
+ precisions: Object.freeze(list(e.precisions)), explicitOnly: e.explicitOnly !== 0, options: Object.freeze(list(e.options)),
72
+ installed: e.installed !== 0, usable: e.usable < 0 ? null : e.usable !== 0, runtimeVersion: e.runtimeVersion || null,
73
+ untested: e.untested !== 0, hidden: e.hidden !== 0, engineClass: classes[e.engineClass] ?? "unknown",
74
+ }));
75
+ }
76
+ /** Whether `engine` may run `family` (`variant`) at `inputSize` ([h, w]; omitted: the variant's own).
77
+ * engine null or "": no engine part (the family's rule). Pure: no download. */
78
+ function modelSupport(family, variant, engine, inputSize) {
79
+ if (typeof family !== "string")
80
+ throw (0, errors_1.invalidArgument)(`model_support: family must be a string, got ${JSON.stringify(family)}`);
81
+ const [w, h] = sizeArgs(inputSize);
82
+ const s = native_1.native.depz_model_support((0, settings_1.currentContext)(), family, str(variant, "variant"), str(engine, "engine"), w, h);
83
+ return Object.freeze({
84
+ ok: s.ok !== 0, code: s.code || null, reason: s.reason, precision: s.precision || null, verified: s.verified !== 0,
85
+ regionKind: s.regionKind === C.DEPZ_INPUT_SIZE_ANY ? "any" : "listed",
86
+ regionSizes: Object.freeze(pairs(s.regionSizes, s.regionSizeCount)),
87
+ regionLimits: Object.freeze({
88
+ minWidth: s.regionLimitsMinWidth, minHeight: s.regionLimitsMinHeight, goodWidth: s.regionLimitsGoodWidth,
89
+ goodHeight: s.regionLimitsGoodHeight, inputMultiple: s.regionLimitsInputMultiple,
90
+ leftMarginMaxPx: s.regionLimitsLeftMarginMaxPx, leftMarginShare: s.regionLimitsLeftMarginShare,
91
+ }),
92
+ minInput: s.minInputHeight > 0 || s.minInputWidth > 0 ? Object.freeze([s.minInputHeight, s.minInputWidth]) : null,
93
+ });
94
+ }
95
+ /** Which input sizes a model accepts on an engine: [kind, [[h, w], ...]] (input_size_support). */
96
+ function inputSizeSupport(family, engine) {
97
+ if (typeof family !== "string")
98
+ throw (0, errors_1.invalidArgument)("input_size_support: family must be a string");
99
+ const s = native_1.native.depz_model_input_sizes((0, settings_1.currentContext)(), family, str(engine, "engine"));
100
+ return [s.kind === C.DEPZ_INPUT_SIZE_ANY ? "any" : "listed", pairs(s.sizes, s.count)];
101
+ }
102
+ /** An engine slug's two parts: [kind (lowercased), device_or_ep] ("openvino-GPU.0": ["openvino", "GPU.0"]). */
103
+ function parseEngineSlug(slug) {
104
+ const j = JSON.parse(native_1.native.depz_engine_parse_slug(slug));
105
+ return [j.kind, j.device_or_ep];
106
+ }
107
+ /** The model to run on engine when nobody chooses one, on this host: [family, variant], or null. */
108
+ function defaultModel(engine) {
109
+ const d = native_1.native.depz_model_default((0, settings_1.currentContext)(), str(engine, "engine"));
110
+ return d.hasDefault ? [d.family, d.variant] : null;
111
+ }
112
+ /** The files a download of the model fetches (and buildInference runs), absolute under the cache root,
113
+ * the entry point first ([] for a classical matcher). Downloads nothing. */
114
+ function modelFiles(family, variant, engine, inputSize) {
115
+ const [w, h] = sizeArgs(inputSize);
116
+ return JSON.parse(native_1.native.depz_model_files((0, settings_1.currentContext)(), str(family, "family"), str(variant, "variant"), str(engine, "engine"), w, h));
117
+ }
118
+ /** What the engine caches hold for one model variant. */
119
+ function engineCacheStatus(family, variant) {
120
+ const s = native_1.native.depz_engine_cache_status((0, settings_1.currentContext)(), str(family, "family"), str(variant, "variant"));
121
+ return Object.freeze({ tensorrtPlans: s.tensorrtPlans, tensorrtBytes: s.tensorrtBytes, tensorrtOptLevel: s.tensorrtOptLevel < 0 ? null : s.tensorrtOptLevel });
122
+ }
123
+ /** Deletes engine caches (downloaded models are kept); what was deleted. kinds: null for all. */
124
+ function clearEngineCaches(kinds, options = {}) {
125
+ if (kinds !== null && (!Array.isArray(kinds) || kinds.some((k) => typeof k !== "string")))
126
+ throw (0, errors_1.invalidArgument)("kinds must be a list of strings or null");
127
+ const text = native_1.native.depz_engine_caches_clear((0, settings_1.currentContext)(), kinds === null ? null : kinds.join(","), str(options.family, "family"), str(options.variant, "variant"));
128
+ return JSON.parse(text);
129
+ }
130
+ /** The native cancel flag of an AbortSignal. Internal. */
131
+ function flagOf(signal) {
132
+ if (signal === undefined)
133
+ return null;
134
+ const flag = new native_1.native.NativeFlag();
135
+ if (signal.aborted)
136
+ flag.set();
137
+ else
138
+ signal.addEventListener("abort", () => flag.set(), { once: true });
139
+ return flag;
140
+ }
141
+ /** A model loaded on an engine (buildInference). */
142
+ class Inference {
143
+ /** @internal */
144
+ _h;
145
+ /** @internal */
146
+ constructor(handle) {
147
+ this._h = handle;
148
+ }
149
+ get info() {
150
+ const i = native_1.native.depz_inference_info(this._h);
151
+ return Object.freeze({
152
+ model: i.model, variant: i.variant, engine: i.engine,
153
+ inputSize: i.inputWidth > 0 ? Object.freeze([i.inputHeight, i.inputWidth]) : null,
154
+ mono: i.mono !== 0, outputsDepth: i.outputsDepth !== 0, maxConcurrentRuns: i.maxConcurrentRuns,
155
+ });
156
+ }
157
+ /** Sets one of the model's own controls (a catalog model's: SGBM's block_size, a monocular
158
+ * model's depth_scale, ...), coerced as in a pipeline's "inference" scope. */
159
+ controlSet(name, value) {
160
+ native_1.native.depz_inference_control_set(this._h, name, typeof value === "boolean" ? (value ? 1 : 0) : value);
161
+ }
162
+ /** Releases the model now (a depth stage that runs it keeps its own reference). */
163
+ release() {
164
+ this._h.release();
165
+ }
166
+ }
167
+ exports.Inference = Inference;
168
+ /** Downloads (and checks) the files of a model for an engine and size into the cache; the paths. */
169
+ async function downloadModel(family, variant, options = {}) {
170
+ if (typeof family !== "string" || typeof variant !== "string")
171
+ throw (0, errors_1.invalidArgument)("download_model: family and variant are strings");
172
+ const [w, h] = sizeArgs(options.inputSize);
173
+ const engine = str(options.engine, "engine");
174
+ await native_1.native.depz_model_download((0, settings_1.currentContext)(), family, variant, engine, w, h, options.progress ?? null, flagOf(options.signal));
175
+ return modelFiles(family, variant, engine, options.inputSize);
176
+ }
177
+ /** Whether the files buildInference would use are in the cache. */
178
+ function isModelCached(family, variant, options = {}) {
179
+ const [w, h] = sizeArgs(options.inputSize);
180
+ return native_1.native.depz_model_is_cached((0, settings_1.currentContext)(), family, variant, str(options.engine, "engine"), w, h);
181
+ }
182
+ /** Loads `family` `variant` on an engine (downloads the files on first use, builds the engine). */
183
+ async function buildInference(family, variant, options = {}) {
184
+ if (typeof family !== "string" || typeof variant !== "string")
185
+ throw (0, errors_1.invalidArgument)("build_inference: family and variant are strings");
186
+ const [w, h] = sizeArgs(options.inputSize);
187
+ if (options.progress !== undefined && typeof options.progress !== "function")
188
+ throw (0, errors_1.invalidArgument)("progress must be a function");
189
+ const handle = await native_1.native.depz_inference_create((0, settings_1.currentContext)(), family, variant, str(options.engine, "engine"), w, h, options.progress ?? null, flagOf(options.signal));
190
+ return new Inference(handle);
191
+ }
192
+ /** The depth stage: a model run on every frame of a pipeline (adds disparity, depth, the cloud). */
193
+ class DepthStage {
194
+ model;
195
+ region;
196
+ disparityOffsetPx;
197
+ monoEye;
198
+ /** @internal */
199
+ _h;
200
+ /** The stage that runs `model` on every frame of a pipeline. */
201
+ constructor(model, options = {}) {
202
+ if (!(model instanceof Inference))
203
+ throw (0, errors_1.invalidArgument)("DepthStage takes an Inference");
204
+ const region = options.region ?? null;
205
+ if (region !== null && !(region instanceof calibration_1.InferenceRoi))
206
+ throw (0, errors_1.invalidArgument)("DepthStage: region must be an InferenceRoi or null");
207
+ const offset = options.disparityOffsetPx ?? 0;
208
+ if (!Number.isInteger(offset) || offset < 0)
209
+ throw (0, errors_1.invalidArgument)(`disparity_offset_px must be a whole number >= 0, got ${offset}`);
210
+ const eye = options.monoEye ?? null;
211
+ if (eye !== null)
212
+ (0, calibration_1.eyeValue)(eye, "mono_eye");
213
+ this.model = model;
214
+ this.region = region;
215
+ this.disparityOffsetPx = offset;
216
+ this.monoEye = eye;
217
+ this._h = native_1.native.depz_depth_stage_create(model._h);
218
+ }
219
+ get name() {
220
+ return "depth";
221
+ }
222
+ }
223
+ exports.DepthStage = DepthStage;
@@ -0,0 +1,136 @@
1
+ import type * as R from "./generated/records.g";
2
+ /** An owned reference of an opaque C handle (addon/common.h Handle). */
3
+ export interface NativeHandle {
4
+ release(): void;
5
+ readonly type: string;
6
+ readonly released: boolean;
7
+ }
8
+ /** The cancel flag of a blocking call (an AbortSignal's native side). */
9
+ export interface NativeFlag {
10
+ set(): void;
11
+ }
12
+ export type ProgressFn = (stage: string, done: number, total: number) => void;
13
+ /** A record with its enum members (depz_*_control_at + _enum_member). */
14
+ export type RawControlWithMembers = R.RawControl & {
15
+ enumMembers: R.RawEnumMember[];
16
+ };
17
+ /** The addon's exports, named after the C functions they call. */
18
+ export interface Native {
19
+ NativeHandle: new () => NativeHandle;
20
+ NativeFlag: new () => NativeFlag;
21
+ setErrorFactory(f: (status: number, message: string, details: string) => Error): void;
22
+ depz_version(): string;
23
+ depz_status_name(status: number): string;
24
+ depz_error_set(code: number, message: string | null, details: string | null): void;
25
+ depz_last_error(): {
26
+ status: number;
27
+ message: string;
28
+ details: string;
29
+ };
30
+ abi_layout(): Record<string, {
31
+ size: number;
32
+ fields: Record<string, number>;
33
+ }>;
34
+ depz_host_clock_ns(): bigint;
35
+ depz_board_info(): R.RawBoardInfo;
36
+ depz_context_create(cfg: Partial<R.RawConfig>, log: ((level: number, logger: string, message: string) => void) | null): NativeHandle;
37
+ depz_context_cache_dir(ctx: NativeHandle): string;
38
+ depz_camera_model_of(by: "serial" | "pid" | "sku", key: string): (R.RawCameraModel & {
39
+ formerSkus: string[];
40
+ }) | null;
41
+ depz_calibration_from_json(json: string): NativeHandle;
42
+ depz_calibration_info(cal: NativeHandle): R.RawCalibrationInfo;
43
+ depz_calibration_to_json(cal: NativeHandle): string;
44
+ depz_calibration_rescaled(cal: NativeHandle, width: number, height: number): NativeHandle;
45
+ depz_calibration_controls(cal: NativeHandle): RawControlWithMembers[];
46
+ depz_calibration_with_control(cal: NativeHandle, name: string, value: number | string): NativeHandle;
47
+ depz_calibration_with_canvas(cal: NativeHandle, opt: Partial<R.RawCanvasOptions>, roi: Partial<R.RawRoi> | null): NativeHandle;
48
+ depz_calibration_canvas_layout(cal: NativeHandle): R.RawCanvasLayout;
49
+ depz_calibration_canvas_projection(cal: NativeHandle, eye: number): number[];
50
+ depz_calibration_canvas_map(cal: NativeHandle, eye: number): {
51
+ xy: Int16Array;
52
+ index: Uint16Array;
53
+ };
54
+ depz_calibration_rectify(cal: NativeHandle, eye: number, image: {
55
+ data: Uint8Array;
56
+ width: number;
57
+ height: number;
58
+ strideBytes: number;
59
+ }): Uint8Array;
60
+ depz_calibration_disparity_to_depth(cal: NativeHandle, disparity: Float32Array, width: number, height: number): Float32Array;
61
+ depz_calibration_depth_to_point_cloud(cal: NativeHandle, depth: Float32Array, width: number, height: number): Float32Array;
62
+ depz_frame_info(frame: NativeHandle): R.RawFrameInfo;
63
+ depz_frame_timing(frame: NativeHandle): R.RawFrameTiming | null;
64
+ depz_frame_image(frame: NativeHandle, kind: number): (R.RawImage & {
65
+ buffer: ArrayBuffer;
66
+ }) | null;
67
+ depz_frame_payload(frame: NativeHandle): ArrayBuffer | null;
68
+ depz_source_create_recording(ctx: NativeHandle, path: string, opt: Partial<R.RawReplayOptions>): NativeHandle;
69
+ depz_source_open(source: NativeHandle): Promise<void>;
70
+ depz_source_close(source: NativeHandle): void;
71
+ depz_source_grab(source: NativeHandle, timeoutMs: number): Promise<NativeHandle | number>;
72
+ depz_source_info(source: NativeHandle): R.RawSourceInfo;
73
+ depz_list_models(ctx: NativeHandle): (R.RawModelInfo & {
74
+ variants: R.RawModelVariant[];
75
+ })[];
76
+ depz_describe_engines(ctx: NativeHandle): R.RawEngineInfo[];
77
+ depz_model_support(ctx: NativeHandle, family: string | null, variant: string | null, engine: string | null, width: number, height: number): R.RawModelSupport;
78
+ depz_model_input_sizes(ctx: NativeHandle, family: string | null, engine: string | null): R.RawInputSizes;
79
+ depz_model_default(ctx: NativeHandle, engine: string | null): R.RawModelDefault;
80
+ depz_engine_parse_slug(slug: unknown): string;
81
+ depz_model_files(ctx: NativeHandle, family: string | null, variant: string | null, engine: string | null, width: number, height: number): string;
82
+ depz_engine_cache_status(ctx: NativeHandle, family: string | null, variant: string | null): R.RawEngineCacheStatus;
83
+ depz_engine_caches_clear(ctx: NativeHandle, kinds: string | null, family: string | null, variant: string | null): string;
84
+ depz_inference_create(ctx: NativeHandle, family: string, variant: string, engine: string | null, width: number, height: number, progress: ProgressFn | null, cancel: NativeFlag | null): Promise<NativeHandle>;
85
+ depz_inference_info(inf: NativeHandle): R.RawInferenceInfo;
86
+ depz_depth_stage_create(inf: NativeHandle): NativeHandle;
87
+ depz_pipeline_create(source: NativeHandle, stages: NativeHandle[], cfg: Partial<R.RawPipelineConfig>, recalibration: Partial<R.RawRecalConfig> | null, roi: Partial<R.RawRoi> | null): NativeHandle;
88
+ depz_pipeline_start(p: NativeHandle, progress: ProgressFn | null, cancel: NativeFlag | null): Promise<void>;
89
+ depz_pipeline_get(p: NativeHandle, timeoutMs: number): Promise<NativeHandle | number>;
90
+ depz_pipeline_stop(p: NativeHandle): Promise<void>;
91
+ depz_pipeline_info(p: NativeHandle): R.RawPipelineInfo;
92
+ depz_pipeline_source_info(p: NativeHandle): R.RawSourceInfo;
93
+ depz_pipeline_metrics(p: NativeHandle): R.RawPipelineMetrics;
94
+ depz_pipeline_last_error(p: NativeHandle): {
95
+ status: number;
96
+ message: string;
97
+ };
98
+ depz_pipeline_calibration(p: NativeHandle): NativeHandle;
99
+ depz_list_cameras(ctx: NativeHandle): R.RawAttachedCamera[];
100
+ depz_scan_cameras(ctx: NativeHandle, web: boolean | null): Promise<{
101
+ status: R.RawCameraStatus;
102
+ camera: NativeHandle | null;
103
+ }[]>;
104
+ depz_find_camera(ctx: NativeHandle, serial: string | null, web: boolean | null): Promise<NativeHandle>;
105
+ depz_camera_info(camera: NativeHandle): R.RawCameraInfo;
106
+ depz_camera_modes(camera: NativeHandle): R.RawMode[];
107
+ depz_camera_calibration(camera: NativeHandle): NativeHandle | null;
108
+ depz_camera_family_modes(family: string): R.RawMode[];
109
+ depz_camera_family_controls(family: string): RawControlWithMembers[];
110
+ depz_source_create_camera(camera: NativeHandle, mode: string | null, eyeWidth: number, eyeHeight: number): NativeHandle;
111
+ depz_source_controls(source: NativeHandle): RawControlWithMembers[];
112
+ depz_source_control_get(source: NativeHandle, name: string): R.RawControl;
113
+ depz_source_control_set_number(source: NativeHandle, name: string, value: number): void;
114
+ depz_source_replay_info(source: NativeHandle): R.RawReplayInfo;
115
+ depz_source_replay(source: NativeHandle, what: "pause" | "resume" | "seek_us" | "seek_frame" | "step" | "set_loop", arg?: number | boolean): void;
116
+ depz_source_recording_tracks_json(source: NativeHandle): string;
117
+ depz_source_embedded_camera_json(source: NativeHandle): string;
118
+ depz_source_calibration(source: NativeHandle, which: "base" | "active"): NativeHandle | null;
119
+ depz_replay(p: NativeHandle, what: "pause" | "resume" | "seek_us" | "seek_frame" | "step", arg?: number): void;
120
+ depz_replay_status(p: NativeHandle): R.RawReplayStatus;
121
+ depz_controls(p: NativeHandle, scope: number, owner: string | null): RawControlWithMembers[];
122
+ depz_control_get(p: NativeHandle, scope: number, owner: string | null, name: string): RawControlWithMembers;
123
+ depz_control_set(p: NativeHandle, scope: number, owner: string | null, name: string, value: number | string): void;
124
+ depz_controls_set_many_json(p: NativeHandle, scope: number, owner: string | null, values: string): string;
125
+ depz_controls_reset(p: NativeHandle, scope: number, owner: string | null): string;
126
+ depz_recording_start(p: NativeHandle, path: string, opt: Partial<R.RawRecordingOptions>): void;
127
+ depz_recording_stop(p: NativeHandle): Promise<R.RawRecordingResult>;
128
+ depz_recording_pause_resume(p: NativeHandle, pause: boolean): void;
129
+ depz_recording_status(p: NativeHandle): R.RawRecordingStatus;
130
+ depz_recording_capture_still(p: NativeHandle, path: string, timeoutMs: number): Promise<R.RawRecordingResult>;
131
+ depz_model_download(ctx: NativeHandle, family: string, variant: string, engine: string | null, width: number, height: number, progress: ProgressFn | null, cancel: NativeFlag | null): Promise<void>;
132
+ depz_model_is_cached(ctx: NativeHandle, family: string, variant: string, engine: string | null, width: number, height: number): boolean;
133
+ depz_inference_control_set(inf: NativeHandle, name: string, value: number | string): void;
134
+ }
135
+ /** The addon, loaded once. */
136
+ export declare const native: Native;