@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,251 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Calibration = exports.InferenceRoi = void 0;
4
+ exports.cameraModelOfSerial = cameraModelOfSerial;
5
+ exports.cameraModelOfPid = cameraModelOfPid;
6
+ exports.cameraModelOfSku = cameraModelOfSku;
7
+ exports.controlOf = controlOf;
8
+ exports.eyeValue = eyeValue;
9
+ exports.eyeOf = eyeOf;
10
+ exports.pyFloat = pyFloat;
11
+ // SPDX-License-Identifier: Apache-2.0
12
+ // The catalog's camera models (depzcal.codec CameraModel and its three lookups) and Calibration
13
+ // (the reference's Calibration: from_json, to_json, rescaled, the controls; the canvas of the C
14
+ // ABI: depz_calibration_with_canvas and the calls on it).
15
+ const C = require("./generated/constants.g");
16
+ const errors_1 = require("./errors");
17
+ const native_1 = require("./native");
18
+ function cameraModelOf(by, key) {
19
+ if (typeof key !== "string")
20
+ throw (0, errors_1.invalidArgument)(`camera_model_of_${by} takes a string`);
21
+ const m = native_1.native.depz_camera_model_of(by, key);
22
+ if (m === null)
23
+ return null;
24
+ return Object.freeze({
25
+ id: m.id, sku: m.sku, formerSkus: Object.freeze([...m.formerSkus]), serialPrefix: m.serialPrefix,
26
+ cameraFamily: m.cameraFamily, firmwareImage: m.firmwareImage, usbPid: m.usbPid, eyeRotationDeg: m.eyeRotationDeg,
27
+ isMono: m.isMono !== 0, lensClass: m.lensClass, baselineM: Number.isNaN(m.baselineM) ? null : m.baselineM,
28
+ name: m.name, shortName: m.shortName,
29
+ });
30
+ }
31
+ /** The model a valid serial names (the bare serial, "VRX6L1PSJ4"); null for a serial that is not valid. */
32
+ function cameraModelOfSerial(serial) {
33
+ return cameraModelOf("serial", serial);
34
+ }
35
+ /** The model of a USB product id: 4 hexadecimal digits, any case ("e000"), or the number (0xe000);
36
+ * null when none. */
37
+ function cameraModelOfPid(pid) {
38
+ if (typeof pid === "number") {
39
+ if (!Number.isInteger(pid) || pid < 0 || pid > 0xffff)
40
+ return null;
41
+ pid = pid.toString(16).padStart(4, "0");
42
+ }
43
+ return cameraModelOf("pid", pid);
44
+ }
45
+ /** The model of a catalog sku, of today or a former one; null when none. */
46
+ function cameraModelOfSku(sku) {
47
+ return cameraModelOf("sku", sku);
48
+ }
49
+ const CONTROL_TYPES = {
50
+ [C.DEPZ_CONTROL_INT]: "int", [C.DEPZ_CONTROL_FLOAT]: "float", [C.DEPZ_CONTROL_BOOL]: "bool", [C.DEPZ_CONTROL_ENUM]: "enum",
51
+ };
52
+ const nanToNull = (v) => (Number.isNaN(v) ? null : v);
53
+ /** A control record of the C ABI as the reference's Control (has_value / has_default 0: None). Internal. */
54
+ function controlOf(c) {
55
+ const text = c.isText !== 0;
56
+ const members = c.enumMembers.map((m) => Object.freeze({ value: text ? m.valueText : m.value, label: m.label }));
57
+ return Object.freeze({
58
+ name: c.name, label: c.label, unit: c.unit, type: CONTROL_TYPES[c.type] ?? "float",
59
+ min: nanToNull(c.min), max: nanToNull(c.max), step: nanToNull(c.step),
60
+ value: c.hasValue === 0 ? null : text ? c.valueText : c.value,
61
+ default: c.hasDefault === 0 ? null : text ? c.defaultText : c.defaultValue,
62
+ enumValues: Object.freeze(members.map((m) => m.value)), enumMembers: Object.freeze(members),
63
+ writable: c.writable !== 0, autoCompanion: c.autoCompanion, updatableByAuto: c.updatableByAuto !== 0,
64
+ });
65
+ }
66
+ /** The C value of an eye; undefined / null: the default (DEPZ_EYE_DEFAULT). Internal. */
67
+ function eyeValue(eye, what = "eye") {
68
+ if (eye === undefined || eye === null)
69
+ return C.DEPZ_EYE_DEFAULT;
70
+ if (eye === "left")
71
+ return C.DEPZ_EYE_LEFT;
72
+ if (eye === "right")
73
+ return C.DEPZ_EYE_RIGHT;
74
+ throw (0, errors_1.invalidArgument)(`${what} must be "left" or "right", got ${JSON.stringify(eye)}`);
75
+ }
76
+ function eyeOf(value) {
77
+ return value === C.DEPZ_EYE_RIGHT ? "right" : "left";
78
+ }
79
+ /** A number as Python's repr of a float writes it ("0.0", "1e-09"): the reference's messages. Internal. */
80
+ function pyFloat(x) {
81
+ if (Number.isNaN(x))
82
+ return "nan";
83
+ if (!Number.isFinite(x))
84
+ return x > 0 ? "inf" : "-inf";
85
+ if (Object.is(x, -0))
86
+ return "-0.0";
87
+ if (Number.isInteger(x) && Math.abs(x) < 1e16)
88
+ return x.toFixed(1);
89
+ return String(x).replace(/e([+-])(\d)$/, "e$10$2");
90
+ }
91
+ /** A region of the rectified frame (the reference's InferenceRoi): fractions, and the width the
92
+ * whole frame has at the model's scale. */
93
+ class InferenceRoi {
94
+ x;
95
+ y;
96
+ w;
97
+ h;
98
+ frameWidth;
99
+ /** Refuses (invalid_argument) a region outside the frame or a frame width under 32. */
100
+ constructor(x, y, w, h, frameWidth) {
101
+ const v = { x, y, w, h };
102
+ for (const name of ["x", "y", "w", "h"]) {
103
+ if (typeof v[name] !== "number" || !Number.isFinite(v[name]))
104
+ throw (0, errors_1.invalidArgument)(`InferenceRoi.${name} must be a number`);
105
+ }
106
+ if (typeof frameWidth !== "number" || !Number.isFinite(frameWidth))
107
+ throw (0, errors_1.invalidArgument)("InferenceRoi.frame_width must be a whole number");
108
+ frameWidth = Math.trunc(frameWidth);
109
+ if (w <= 0 || h <= 0)
110
+ throw (0, errors_1.invalidArgument)("InferenceRoi: w and h must be positive");
111
+ if (x < 0 || y < 0 || x + w > 1 + 1e-6 || y + h > 1 + 1e-6) {
112
+ throw (0, errors_1.invalidArgument)(`InferenceRoi must lie inside the frame: 0 ≤ x, y and x + w ≤ 1, y + h ≤ 1 (got ${pyFloat(x)}, ${pyFloat(y)}, ${pyFloat(w)}, ${pyFloat(h)})`);
113
+ }
114
+ if (frameWidth < 32)
115
+ throw (0, errors_1.invalidArgument)("InferenceRoi.frame_width must be at least 32");
116
+ this.x = x;
117
+ this.y = y;
118
+ this.w = w;
119
+ this.h = h;
120
+ this.frameWidth = frameWidth;
121
+ Object.freeze(this);
122
+ }
123
+ /** Internal: the C record. */
124
+ toRaw() {
125
+ return { x: this.x, y: this.y, w: this.w, h: this.h, frameWidth: this.frameWidth };
126
+ }
127
+ }
128
+ exports.InferenceRoi = InferenceRoi;
129
+ // ---- Calibration -------------------------------------------------------------------------------------
130
+ /** A stereo (or mono) calibration. The C value under it never changes: controlSet takes a new one. */
131
+ class Calibration {
132
+ /** @internal */
133
+ _h;
134
+ /** @internal Use Calibration.fromJson, a source's or a pipeline's calibration. */
135
+ constructor(handle) {
136
+ if (!(handle instanceof native_1.native.NativeHandle) || handle.type !== "depz_calibration") {
137
+ throw (0, errors_1.invalidArgument)("Calibration is made by Calibration.fromJson, a source or a pipeline");
138
+ }
139
+ this._h = handle;
140
+ }
141
+ /** A calibration read from the SDK calibration JSON (contracts/calibration/sdk_json.md). */
142
+ static fromJson(text) {
143
+ if (typeof text !== "string")
144
+ throw (0, errors_1.invalidArgument)("Calibration.from_json takes a string");
145
+ return new Calibration(native_1.native.depz_calibration_from_json(text));
146
+ }
147
+ /** The SDK calibration JSON. */
148
+ toJson() {
149
+ return native_1.native.depz_calibration_to_json(this._h);
150
+ }
151
+ get info() {
152
+ return native_1.native.depz_calibration_info(this._h);
153
+ }
154
+ /** "opencv5", "opencv8", "kb4", "eucm", "splined" (contracts/calibration/lens_models.json). */
155
+ get lensModel() {
156
+ return this.info.lensModel;
157
+ }
158
+ get isStereo() {
159
+ return this.info.isStereo !== 0;
160
+ }
161
+ /** [width, height] of the eye the calibration is for. */
162
+ get imageSize() {
163
+ const i = this.info;
164
+ return [i.imageWidth, i.imageHeight];
165
+ }
166
+ /** The baseline in metres; NaN for a mono calibration (the C ABI's; the reference: its stored number). */
167
+ get baselineM() {
168
+ return this.info.baselineM;
169
+ }
170
+ /** The rectified focal length at the image size, px (a latitude-longitude model: pixels per radian). */
171
+ get focalNativePx() {
172
+ return this.info.focalNativePx;
173
+ }
174
+ /** The canvas's focal length (withCanvas); NaN without a canvas. */
175
+ get focalCanvasPx() {
176
+ return this.info.focalCanvasPx;
177
+ }
178
+ /** A new calibration for eyes of width x height (the same aspect ratio); no canvas. */
179
+ rescaled(width, height) {
180
+ return new Calibration(native_1.native.depz_calibration_rescaled(this._h, width, height));
181
+ }
182
+ /** The calibration's controls with their values in it. */
183
+ controls() {
184
+ return native_1.native.depz_calibration_controls(this._h).map(controlOf);
185
+ }
186
+ /** A control's value; undefined for a name it has not. */
187
+ controlGet(name) {
188
+ return this.controls().find((c) => c.name === name)?.value;
189
+ }
190
+ /** Sets a control, coerced as the reference's control_set (clamped, snapped); this calibration
191
+ * takes the new value (the rectification made again). Returns the value in force. */
192
+ controlSet(name, value) {
193
+ if (typeof name !== "string")
194
+ throw (0, errors_1.invalidArgument)("control_set: name must be a string");
195
+ if (typeof value === "boolean")
196
+ value = value ? 1 : 0;
197
+ if (typeof value !== "number" && typeof value !== "string")
198
+ throw (0, errors_1.invalidArgument)(`control_set ${name}: a number or a text`);
199
+ const next = native_1.native.depz_calibration_with_control(this._h, name, value);
200
+ this._h = next;
201
+ return this.controlGet(name);
202
+ }
203
+ /** A new calibration ready to rectify onto a canvas (its maps, layout and projection). */
204
+ withCanvas(options) {
205
+ const o = options ?? {};
206
+ const roi = o.roi ?? null;
207
+ if (roi !== null && !(roi instanceof InferenceRoi))
208
+ throw (0, errors_1.invalidArgument)("roi must be an InferenceRoi or null");
209
+ return new Calibration(native_1.native.depz_calibration_with_canvas(this._h, {
210
+ canvasWidth: o.canvasWidth, canvasHeight: o.canvasHeight, eyeWidth: o.eyeWidth ?? 0, eyeHeight: o.eyeHeight ?? 0,
211
+ rightShiftPx: o.rightShiftPx ?? 0, eye: eyeValue(o.eye),
212
+ }, roi === null ? null : roi.toRaw()));
213
+ }
214
+ /** Where the rectified eye sits in the canvas (no canvas: invalid_state). */
215
+ canvasLayout() {
216
+ const l = native_1.native.depz_calibration_canvas_layout(this._h);
217
+ return Object.freeze({
218
+ scale: l.scale, validW: l.validW, validH: l.validH, padX: l.padX, padY: l.padY, eyeW: l.eyeW, eyeH: l.eyeH,
219
+ frameX: l.frameX, frameY: l.frameY, frameW: l.frameW, frameH: l.frameH, rightShiftPx: l.rightShiftPx,
220
+ eye: eyeOf(l.eye), canvasWidth: l.canvasWidth, canvasHeight: l.canvasHeight,
221
+ isLatlon: l.isLatlon !== 0, isBorderReplicate: l.isBorderReplicate !== 0,
222
+ });
223
+ }
224
+ /** The 3 x 4 projection (row major) of an eye on a pinhole canvas; no eye: the canvas's. */
225
+ canvasProjection(eye) {
226
+ return native_1.native.depz_calibration_canvas_projection(this._h, eyeValue(eye));
227
+ }
228
+ /** The canvas's remap of an eye in OpenCV's fixed point (CV_16SC2 xy + CV_16UC1 index). */
229
+ canvasMap(eye) {
230
+ return native_1.native.depz_calibration_canvas_map(this._h, eyeValue(eye));
231
+ }
232
+ /** A raw eye (BGR8) rectified onto the canvas: canvasWidth x canvasHeight BGR8. */
233
+ rectify(eye, image) {
234
+ return native_1.native.depz_calibration_rectify(this._h, eyeValue(eye), {
235
+ data: image.data, width: image.width, height: image.height, strideBytes: image.strideBytes ?? 3 * image.width,
236
+ });
237
+ }
238
+ /** Disparity on the canvas (px, width x height) to depth in metres; 0 where d <= 0.1 px. */
239
+ disparityToDepth(disparity, width, height) {
240
+ return native_1.native.depz_calibration_disparity_to_depth(this._h, disparity, width, height);
241
+ }
242
+ /** Depth (m) to points (x, y, z per pixel) in the rectified frame of the canvas eye. */
243
+ depthToPointCloud(depth, width, height) {
244
+ return native_1.native.depz_calibration_depth_to_point_cloud(this._h, depth, width, height);
245
+ }
246
+ /** Releases the C value now (else the garbage collector does). */
247
+ release() {
248
+ this._h.release();
249
+ }
250
+ }
251
+ exports.Calibration = Calibration;
@@ -0,0 +1,91 @@
1
+ import { ErrorCode } from "./errors";
2
+ import { Calibration, type Control } from "./calibration";
3
+ import { type NativeHandle } from "./native";
4
+ /** An attached camera as the system lists it, none opened (the reference's AttachedCamera). */
5
+ export interface AttachedCamera {
6
+ readonly name: string;
7
+ readonly serial: string;
8
+ /** The system's name of its capture device, for people (/dev/videoN, ...). */
9
+ readonly device: string;
10
+ /** This user may open it; null where the system does not tell without opening. */
11
+ readonly accessible: boolean | null;
12
+ }
13
+ /** The attached DEPZ cameras, found without opening or reading any. */
14
+ export declare function listCameras(): AttachedCamera[];
15
+ /** One capture mode the SDK offers (the reference's CaptureMode with its geometry). */
16
+ export interface CaptureMode {
17
+ /** "640x360@30/MJPG/stereo": a stable key. */
18
+ readonly slug: string;
19
+ /** The raw frame (side by side for stereo). */
20
+ readonly width: number;
21
+ readonly height: number;
22
+ readonly eyeWidth: number;
23
+ readonly eyeHeight: number;
24
+ /** The rate asked for. */
25
+ readonly fps: number;
26
+ readonly fourcc: string;
27
+ readonly stereo: boolean;
28
+ readonly isDefault: boolean;
29
+ readonly scaleX: number;
30
+ readonly scaleY: number;
31
+ readonly cropX: number;
32
+ readonly cropY: number;
33
+ /** A single-eye mode of a two-eye camera: "left" / "right"; "" otherwise (as the reference). */
34
+ readonly eye: "left" | "right" | "";
35
+ readonly kind: string;
36
+ }
37
+ /** A camera family's offered capture modes, without a camera ("varius", "minima", ...). */
38
+ export declare function cameraFamilyModes(cameraFamily: string): CaptureMode[];
39
+ /** A camera family's controls on this system, without a camera (values unknown: null). */
40
+ export declare function cameraFamilyControls(cameraFamily: string): Control[];
41
+ /** Where a camera's calibration was read from: its USB name, its flash, or the web copy. */
42
+ export type CalibrationSource = "name" | "flash" | "web";
43
+ /** A resolved camera: identity, capture modes, calibration. A value: holds no device open. */
44
+ export declare class CameraInfo {
45
+ /** @internal */
46
+ readonly _h: NativeHandle;
47
+ readonly serial: string;
48
+ readonly name: string;
49
+ readonly cameraFamily: string;
50
+ readonly eyeRotationDeg: number;
51
+ readonly isStereo: boolean;
52
+ /** F, N, V of the camera's name; null when not known. */
53
+ readonly firmware: number | null;
54
+ readonly calibrationNumber: number | null;
55
+ readonly calibrationScheme: number | null;
56
+ /** 4 lower-case hex digits; null when not known. */
57
+ readonly calibrationCrc: string | null;
58
+ readonly calibrationSource: CalibrationSource | null;
59
+ /** @internal Made by findCamera and scanCameras. */
60
+ constructor(handle: NativeHandle);
61
+ /** The capture modes the SDK offers for it. */
62
+ get modes(): CaptureMode[];
63
+ /** The default capture mode; null when it offers none. */
64
+ get mode(): CaptureMode | null;
65
+ /** The calibration stored in the camera; null when it has none. */
66
+ get baseCalibration(): Calibration | null;
67
+ /** Its family's controls (values unknown: a source's controls read them). */
68
+ get controls(): Control[];
69
+ /** Releases the camera's record now. */
70
+ release(): void;
71
+ }
72
+ /** One attached camera and what it can be used for (the reference's CameraStatus). */
73
+ export interface CameraStatus {
74
+ readonly serial: string;
75
+ readonly name: string;
76
+ readonly state: "usable" | "needs_update" | "unusable" | "busy";
77
+ /** null for a usable camera, else why not. */
78
+ readonly code: ErrorCode | null;
79
+ /** The resolved camera of a usable one. */
80
+ readonly camera: CameraInfo | null;
81
+ }
82
+ /** The options of scanCameras and findCamera. */
83
+ export interface ScanOptions {
84
+ /** false: no network for this call (the calibration from the camera alone); default: the settings'. */
85
+ web?: boolean;
86
+ }
87
+ /** Every attached DEPZ camera, read (a Promise). */
88
+ export declare function scanCameras(options?: ScanOptions): Promise<CameraStatus[]>;
89
+ /** The attached camera with this serial (case ignored), freshly resolved; none given: the first
90
+ * usable one. Not found: DepzError camera_not_found. */
91
+ export declare function findCamera(serial?: string | null, options?: ScanOptions): Promise<CameraInfo>;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CameraInfo = void 0;
4
+ exports.listCameras = listCameras;
5
+ exports.cameraFamilyModes = cameraFamilyModes;
6
+ exports.cameraFamilyControls = cameraFamilyControls;
7
+ exports.scanCameras = scanCameras;
8
+ exports.findCamera = findCamera;
9
+ // SPDX-License-Identifier: Apache-2.0
10
+ // Cameras: identity is the serial (the reference's system_info().cameras, scan_cameras,
11
+ // find_camera, CameraInfo, CaptureMode, camera_family_controls). Listing opens nothing; a scan
12
+ // and a find read each camera (its name, flash and, when the settings allow, the web) and are
13
+ // Promises.
14
+ const C = require("./generated/constants.g");
15
+ const errors_1 = require("./errors");
16
+ const calibration_1 = require("./calibration");
17
+ const native_1 = require("./native");
18
+ const settings_1 = require("./settings");
19
+ /** The attached DEPZ cameras, found without opening or reading any. */
20
+ function listCameras() {
21
+ return native_1.native.depz_list_cameras((0, settings_1.currentContext)()).map((a) => Object.freeze({
22
+ name: a.name, serial: a.serial, device: a.device, accessible: a.accessible < 0 ? null : a.accessible !== 0,
23
+ }));
24
+ }
25
+ function modeOf(m) {
26
+ return Object.freeze({
27
+ slug: m.slug, width: m.width, height: m.height, eyeWidth: m.eyeWidth, eyeHeight: m.eyeHeight, fps: m.fps,
28
+ fourcc: m.fourcc, stereo: m.stereo !== 0, isDefault: m.isDefault !== 0, scaleX: m.scaleX, scaleY: m.scaleY,
29
+ cropX: m.cropX, cropY: m.cropY, eye: m.eye === "left" || m.eye === "right" ? m.eye : "", kind: m.kind,
30
+ });
31
+ }
32
+ /** A camera family's offered capture modes, without a camera ("varius", "minima", ...). */
33
+ function cameraFamilyModes(cameraFamily) {
34
+ return native_1.native.depz_camera_family_modes(cameraFamily).map(modeOf);
35
+ }
36
+ /** A camera family's controls on this system, without a camera (values unknown: null). */
37
+ function cameraFamilyControls(cameraFamily) {
38
+ return native_1.native.depz_camera_family_controls(cameraFamily).map((c) => (0, calibration_1.controlOf)(c));
39
+ }
40
+ /** A resolved camera: identity, capture modes, calibration. A value: holds no device open. */
41
+ class CameraInfo {
42
+ /** @internal */
43
+ _h;
44
+ serial;
45
+ name;
46
+ cameraFamily;
47
+ eyeRotationDeg;
48
+ isStereo;
49
+ /** F, N, V of the camera's name; null when not known. */
50
+ firmware;
51
+ calibrationNumber;
52
+ calibrationScheme;
53
+ /** 4 lower-case hex digits; null when not known. */
54
+ calibrationCrc;
55
+ calibrationSource;
56
+ /** @internal Made by findCamera and scanCameras. */
57
+ constructor(handle) {
58
+ if (!(handle instanceof native_1.native.NativeHandle) || handle.type !== "depz_camera")
59
+ throw (0, errors_1.invalidArgument)("CameraInfo is made by findCamera or scanCameras");
60
+ this._h = handle;
61
+ const i = native_1.native.depz_camera_info(handle);
62
+ const sources = {
63
+ [C.DEPZ_CALIBRATION_SOURCE_NAME]: "name", [C.DEPZ_CALIBRATION_SOURCE_FLASH]: "flash", [C.DEPZ_CALIBRATION_SOURCE_WEB]: "web",
64
+ };
65
+ this.serial = i.serial;
66
+ this.name = i.name;
67
+ this.cameraFamily = i.cameraFamily;
68
+ this.eyeRotationDeg = i.eyeRotationDeg;
69
+ this.isStereo = i.isStereo !== 0;
70
+ this.firmware = i.hasFirmware ? i.firmware : null;
71
+ this.calibrationNumber = i.hasCalibrationNumber ? i.calibrationNumber : null;
72
+ this.calibrationScheme = i.hasCalibrationScheme ? i.calibrationScheme : null;
73
+ this.calibrationCrc = i.calibrationCrc || null;
74
+ this.calibrationSource = sources[i.calibrationSource] ?? null;
75
+ }
76
+ /** The capture modes the SDK offers for it. */
77
+ get modes() {
78
+ return native_1.native.depz_camera_modes(this._h).map(modeOf);
79
+ }
80
+ /** The default capture mode; null when it offers none. */
81
+ get mode() {
82
+ const ms = this.modes;
83
+ return ms.find((m) => m.isDefault) ?? ms[0] ?? null;
84
+ }
85
+ /** The calibration stored in the camera; null when it has none. */
86
+ get baseCalibration() {
87
+ const h = native_1.native.depz_camera_calibration(this._h);
88
+ return h === null ? null : new calibration_1.Calibration(h);
89
+ }
90
+ /** Its family's controls (values unknown: a source's controls read them). */
91
+ get controls() {
92
+ return cameraFamilyControls(this.cameraFamily);
93
+ }
94
+ /** Releases the camera's record now. */
95
+ release() {
96
+ this._h.release();
97
+ }
98
+ }
99
+ exports.CameraInfo = CameraInfo;
100
+ /** Every attached DEPZ camera, read (a Promise). */
101
+ async function scanCameras(options = {}) {
102
+ const states = {
103
+ [C.DEPZ_CAMERA_USABLE]: "usable", [C.DEPZ_CAMERA_NEEDS_UPDATE]: "needs_update", [C.DEPZ_CAMERA_UNUSABLE]: "unusable",
104
+ [C.DEPZ_CAMERA_BUSY]: "busy",
105
+ };
106
+ const list = await native_1.native.depz_scan_cameras((0, settings_1.currentContext)(), options.web ?? null);
107
+ return list.map(({ status, camera }) => Object.freeze({
108
+ serial: status.serial, name: status.name, state: states[status.state] ?? "unusable",
109
+ code: status.code === 0 ? null : status.code, camera: camera === null ? null : new CameraInfo(camera),
110
+ }));
111
+ }
112
+ /** The attached camera with this serial (case ignored), freshly resolved; none given: the first
113
+ * usable one. Not found: DepzError camera_not_found. */
114
+ async function findCamera(serial = null, options = {}) {
115
+ if (serial !== null && typeof serial !== "string")
116
+ throw (0, errors_1.invalidArgument)(`find_camera: serial must be a string, got ${JSON.stringify(serial)}`);
117
+ return new CameraInfo(await native_1.native.depz_find_camera((0, settings_1.currentContext)(), serial, options.web ?? null));
118
+ }
@@ -0,0 +1,25 @@
1
+ import { ErrorCode } from "./generated/error_code.g";
2
+ export { ErrorCode };
3
+ /** The code's name as in errors.json ("camera_busy"); "unknown" for a value it has not. */
4
+ export declare function errorCodeName(code: ErrorCode): string;
5
+ /** What the code means (errors.json); "" for a value it has not. */
6
+ export declare function errorCodeMeaning(code: ErrorCode): string;
7
+ /** The code of a name ("camera_busy"); undefined for a name errors.json has not. */
8
+ export declare function errorCodeOf(name: string): ErrorCode | undefined;
9
+ /** Every failure of the SDK: a stable code, a short English line for logs, and details. */
10
+ export declare class DepzError extends Error {
11
+ /** The code (its frozen value is the C status; errorCodeName gives "camera_busy"). */
12
+ readonly code: ErrorCode;
13
+ /** What the failure concerns (the serial, the path, the engine, ...): a JSON object. */
14
+ readonly details: Record<string, unknown>;
15
+ /** No message: the code's meaning (errors.json); no details: {}. */
16
+ constructor(code: ErrorCode, message?: string | null, details?: Record<string, unknown> | null);
17
+ /** "DepzError(<name>): <message>". */
18
+ toString(): string;
19
+ }
20
+ /** The DepzError of a C status, message and details text (the C ABI's last error). A status
21
+ * errors.json has not is internal, with the status in the details; details that are not a JSON
22
+ * object are kept as their text under "details" (c_api.md section 6). */
23
+ export declare function errorOfStatus(status: number, message: string, detailsJson: string): DepzError;
24
+ /** A binding-side refusal: invalid_argument with the reference's message. */
25
+ export declare function invalidArgument(message: string, details?: Record<string, unknown>): DepzError;
package/dist/errors.js ADDED
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DepzError = exports.ErrorCode = void 0;
4
+ exports.errorCodeName = errorCodeName;
5
+ exports.errorCodeMeaning = errorCodeMeaning;
6
+ exports.errorCodeOf = errorCodeOf;
7
+ exports.errorOfStatus = errorOfStatus;
8
+ exports.invalidArgument = invalidArgument;
9
+ // SPDX-License-Identifier: Apache-2.0
10
+ // The one error model (contracts/errors.json, c_api.md section 6): DepzError(code, message,
11
+ // details), no subclasses. A failed C call throws it with the code, message and details of the
12
+ // C ABI's last error; the binding's own checks throw it with the reference's code.
13
+ const error_code_g_1 = require("./generated/error_code.g");
14
+ Object.defineProperty(exports, "ErrorCode", { enumerable: true, get: function () { return error_code_g_1.ErrorCode; } });
15
+ const NAMES = new Map(error_code_g_1.ERROR_CODES.map(([c, n]) => [c, n]));
16
+ const MEANINGS = new Map(error_code_g_1.ERROR_CODES.map(([c, , m]) => [c, m]));
17
+ const BY_NAME = new Map(error_code_g_1.ERROR_CODES.map(([c, n]) => [n, c]));
18
+ /** The code's name as in errors.json ("camera_busy"); "unknown" for a value it has not. */
19
+ function errorCodeName(code) {
20
+ return NAMES.get(code) ?? "unknown";
21
+ }
22
+ /** What the code means (errors.json); "" for a value it has not. */
23
+ function errorCodeMeaning(code) {
24
+ return MEANINGS.get(code) ?? "";
25
+ }
26
+ /** The code of a name ("camera_busy"); undefined for a name errors.json has not. */
27
+ function errorCodeOf(name) {
28
+ return BY_NAME.get(name);
29
+ }
30
+ /** Every failure of the SDK: a stable code, a short English line for logs, and details. */
31
+ class DepzError extends Error {
32
+ /** The code (its frozen value is the C status; errorCodeName gives "camera_busy"). */
33
+ code;
34
+ /** What the failure concerns (the serial, the path, the engine, ...): a JSON object. */
35
+ details;
36
+ /** No message: the code's meaning (errors.json); no details: {}. */
37
+ constructor(code, message, details) {
38
+ super(message ? message : errorCodeMeaning(code));
39
+ this.name = "DepzError";
40
+ this.code = code;
41
+ this.details = details ?? {};
42
+ }
43
+ /** "DepzError(<name>): <message>". */
44
+ toString() {
45
+ return `DepzError(${errorCodeName(this.code)}): ${this.message}`;
46
+ }
47
+ }
48
+ exports.DepzError = DepzError;
49
+ /** The DepzError of a C status, message and details text (the C ABI's last error). A status
50
+ * errors.json has not is internal, with the status in the details; details that are not a JSON
51
+ * object are kept as their text under "details" (c_api.md section 6). */
52
+ function errorOfStatus(status, message, detailsJson) {
53
+ let details;
54
+ try {
55
+ const parsed = detailsJson ? JSON.parse(detailsJson) : {};
56
+ details = parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)
57
+ ? parsed
58
+ : { details: detailsJson };
59
+ }
60
+ catch {
61
+ details = { details: detailsJson };
62
+ }
63
+ if (!NAMES.has(status)) {
64
+ return new DepzError(error_code_g_1.ErrorCode.Internal, message || `status ${status}`, { ...details, status });
65
+ }
66
+ return new DepzError(status, message, details);
67
+ }
68
+ /** A binding-side refusal: invalid_argument with the reference's message. */
69
+ function invalidArgument(message, details) {
70
+ return new DepzError(error_code_g_1.ErrorCode.InvalidArgument, message, details);
71
+ }
@@ -0,0 +1,108 @@
1
+ import type { RawFrameInfo } from "./generated/records.g";
2
+ import { type Eye } from "./calibration";
3
+ import { type NativeHandle } from "./native";
4
+ /** An image's pixels: BGR8 (3 x uint8), F32 (1 x float32), XYZ_F32 (3 x float32). */
5
+ export type PixelFormat = "bgr8" | "f32" | "xyz_f32";
6
+ /** The images a frame may carry. */
7
+ export type ImageKind = "raw" | "left" | "right" | "rectified_left" | "rectified_right" | "disparity" | "depth" | "point_cloud";
8
+ /** One image of a frame: rows of strideBytes over the frame's memory (no copy). */
9
+ export declare class ImageView {
10
+ readonly width: number;
11
+ readonly height: number;
12
+ readonly strideBytes: number;
13
+ readonly format: PixelFormat;
14
+ /** The frame's bytes, height x strideBytes (the frame lives while this buffer does). */
15
+ readonly buffer: ArrayBuffer;
16
+ /** @internal */
17
+ constructor(width: number, height: number, strideBytes: number, format: PixelFormat, buffer: ArrayBuffer);
18
+ /** Values per pixel: 3 (BGR, XYZ) or 1. */
19
+ get channels(): number;
20
+ /** Bytes per pixel. */
21
+ get bytesPerPixel(): number;
22
+ /** The bytes, rows of strideBytes (a view, no copy). */
23
+ get bytes(): Uint8Array;
24
+ /** The pixels row by row without the rows' padding: a view when the rows are packed, else a copy.
25
+ * Uint8Array for BGR8, Float32Array for the float images. */
26
+ pixels(): Uint8Array | Float32Array;
27
+ private packedCopy;
28
+ }
29
+ /** The image of a kind, or null when the frame does not carry that stream. Internal. */
30
+ export declare function imageOf(frame: NativeHandle, kind: ImageKind): ImageView | null;
31
+ /** When the frame's rows were exposed, on the host clock (ns; contracts/camera-timing). */
32
+ export interface FrameTiming {
33
+ readonly exposureStartNs: bigint;
34
+ readonly exposureEndNs: bigint;
35
+ readonly midExposureNs: bigint;
36
+ readonly exposureNs: bigint;
37
+ readonly rowTimeNs: bigint;
38
+ readonly timestampUncertaintyNs: bigint;
39
+ readonly exposureUncertaintyNs: bigint;
40
+ readonly clockDomain: "linux_monotonic" | "windows_qpc" | "macos_mach" | "unknown";
41
+ readonly timeSource: "device_clock" | "arrival" | "unknown";
42
+ /** UTC (Unix epoch ns) = host time + this; null when not known. */
43
+ readonly utcOffsetNs: bigint | null;
44
+ /** Rows per eye of the captured frame; 0 when not known. */
45
+ readonly rows: number;
46
+ }
47
+ /** The pinhole intrinsics of a frame's images, in their pixels. */
48
+ export interface Intrinsics {
49
+ readonly fx: number;
50
+ readonly fy: number;
51
+ readonly cx: number;
52
+ readonly cy: number;
53
+ }
54
+ /** What a frame shares, a pipeline's or a source's. */
55
+ declare abstract class FrameBase {
56
+ /** @internal */
57
+ readonly _h: NativeHandle;
58
+ /** @internal */
59
+ protected readonly _i: RawFrameInfo;
60
+ /** @internal */
61
+ constructor(handle: NativeHandle);
62
+ /** Source-local time of the capture, µs. */
63
+ get ptsUs(): number;
64
+ /** The frame's index in a recording; null live. */
65
+ get sourceFrameIdx(): number | null;
66
+ /** When its rows were exposed; null for a frame without timing. */
67
+ get timing(): FrameTiming | null;
68
+ /** The image of a kind; null when the frame does not carry it. */
69
+ image(kind: ImageKind): ImageView | null;
70
+ /** Releases the frame's reference now (its images stay valid while their buffers live). */
71
+ release(): void;
72
+ }
73
+ /** One frame of a pipeline (the reference's FramePacket). */
74
+ export declare class FramePacket extends FrameBase {
75
+ /** The pipeline's counter. */
76
+ get frameNumber(): number;
77
+ get left(): ImageView | null;
78
+ get right(): ImageView | null;
79
+ get rectifiedLeft(): ImageView | null;
80
+ get rectifiedRight(): ImageView | null;
81
+ get disparity(): ImageView | null;
82
+ get depth(): ImageView | null;
83
+ get pointCloud(): ImageView | null;
84
+ /** The eye depth and the point cloud are in. */
85
+ get eye(): Eye;
86
+ /** The pipeline's disparity offset. */
87
+ get rightShiftPx(): number;
88
+ get isSnapshot(): boolean;
89
+ /** The part of the rectified frame its maps cover (fractions); null for the whole frame. */
90
+ get roi(): {
91
+ readonly x: number;
92
+ readonly y: number;
93
+ readonly w: number;
94
+ readonly h: number;
95
+ } | null;
96
+ /** The intrinsics of its images; null for a source without a calibration. */
97
+ get intrinsics(): Intrinsics | null;
98
+ }
99
+ /** One frame grabbed from a source (the reference's RawFrame). */
100
+ export declare class RawFrame extends FrameBase {
101
+ /** The grab counter (1 for the first grab). */
102
+ get sequence(): number;
103
+ /** The decoded picture (side by side for stereo). */
104
+ get picture(): ImageView | null;
105
+ /** The bytes as the camera sent them (MJPEG, YUYV), no copy; null when none. */
106
+ get payload(): Uint8Array | null;
107
+ }
108
+ export {};