@kubohiroya/turbowarp-camera-source 0.15.0 → 0.17.0
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.
- package/README.ja.md +14 -2
- package/README.md +40 -2
- package/dist/calibration/camera-info.d.ts +2 -0
- package/dist/calibration/camera-info.d.ts.map +1 -1
- package/dist/calibration/camera-info.js +4 -0
- package/dist/calibration/camera-info.js.map +1 -1
- package/dist/camera-source.js +10264 -1728
- package/dist/extension-manifest.json +25 -0
- package/dist/profile.d.ts +1 -1
- package/dist/profile.d.ts.map +1 -1
- package/dist/profile.js +1 -1
- package/dist/profile.js.map +1 -1
- package/lib-editor/schemas/camera-intrinsics-v1.json +346 -0
- package/lib-editor/schemas/editor-legacy-calibration.json +57 -0
- package/lib-editor/schemas/editor-ros-camera-info.json +29 -0
- package/lib-editor/src/calibration/camera-info.d.ts +33 -0
- package/lib-editor/src/calibration/camera-info.js +340 -0
- package/lib-editor/src/calibration/profile.d.ts +46 -0
- package/lib-editor/src/calibration/profile.js +479 -0
- package/lib-editor/src/calibration/types.d.ts +134 -0
- package/lib-editor/src/calibration/types.js +12 -0
- package/lib-editor/src/calibration/yaml.d.ts +20 -0
- package/lib-editor/src/calibration/yaml.js +444 -0
- package/lib-editor/src/editor-schema.d.ts +51 -0
- package/lib-editor/src/editor-schema.js +119 -0
- package/package.json +18 -7
- package/schemas/editor-legacy-calibration.json +57 -0
- package/schemas/editor-ros-camera-info.json +29 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The file a calibration is exchanged in: a ROS `camera_info` YAML document.
|
|
3
|
+
*
|
|
4
|
+
* The profile contract is how this extension holds a calibration; it is not a format anyone outside
|
|
5
|
+
* this family reads. A file an operator carries between machines is better written in the format
|
|
6
|
+
* the tools they will meet already read, and for one camera's intrinsics that is the YAML that
|
|
7
|
+
* ROS's `camera_calibration_parsers` reads and writes -- OpenCV-based pipelines, ROS and ROS 2
|
|
8
|
+
* drivers, and SLAM tools load it as it is.
|
|
9
|
+
*
|
|
10
|
+
* ROS carries what projection needs and nothing about when or how the camera was configured, which
|
|
11
|
+
* is exactly what deciding whether a profile still fits requires. Those members travel in one extra
|
|
12
|
+
* top-level mapping, `turbowarp_camera_source`, named after their owner. ROS's reader looks keys up
|
|
13
|
+
* by name and never enumerates the document, so a file with the extra mapping still loads there,
|
|
14
|
+
* and a file without it is still ROS.
|
|
15
|
+
*
|
|
16
|
+
* A file that lacks the mapping altogether cannot become a profile: when it was calibrated and which
|
|
17
|
+
* run it was are required members, and inventing either would turn "unknown" into a record.
|
|
18
|
+
*/
|
|
19
|
+
import { CAMERA_INTRINSIC_PROFILE_SCHEMA, CAMERA_INTRINSIC_PROFILE_VERSION } from './profile.js';
|
|
20
|
+
import { parseYaml, YamlError } from './yaml.js';
|
|
21
|
+
/** The top-level key holding the members ROS has no place for. */
|
|
22
|
+
export const CAMERA_INFO_EXTENSION_KEY = 'turbowarp_camera_source';
|
|
23
|
+
const MATRIX_TOLERANCE = 1e-6;
|
|
24
|
+
/**
|
|
25
|
+
* Every top-level key a ROS file may have, and the extra mapping.
|
|
26
|
+
*
|
|
27
|
+
* Anything else is refused rather than dropped. A calibration file that carries a key nobody reads
|
|
28
|
+
* is either from a tool that means something by it or has had something pasted into it, and a
|
|
29
|
+
* profile validator that fails closed does not start ignoring members because they arrived in YAML.
|
|
30
|
+
*/
|
|
31
|
+
const ROOT_KEYS = new Set([
|
|
32
|
+
'image_width',
|
|
33
|
+
'image_height',
|
|
34
|
+
'camera_name',
|
|
35
|
+
'camera_matrix',
|
|
36
|
+
'distortion_model',
|
|
37
|
+
'distortion_coefficients',
|
|
38
|
+
'rectification_matrix',
|
|
39
|
+
'projection_matrix',
|
|
40
|
+
'binning_x',
|
|
41
|
+
'binning_y',
|
|
42
|
+
'roi',
|
|
43
|
+
CAMERA_INFO_EXTENSION_KEY
|
|
44
|
+
]);
|
|
45
|
+
/** ROS distortion model names, as `sensor_msgs/distortion_models.hpp` spells them. */
|
|
46
|
+
const PLUMB_BOB = 'plumb_bob';
|
|
47
|
+
const RATIONAL_POLYNOMIAL = 'rational_polynomial';
|
|
48
|
+
const EQUIDISTANT = 'equidistant';
|
|
49
|
+
class CameraInfoRejection extends Error {
|
|
50
|
+
detail;
|
|
51
|
+
constructor(detail) {
|
|
52
|
+
super(detail.message);
|
|
53
|
+
this.detail = detail;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function refuse(code, path, message) {
|
|
57
|
+
throw new CameraInfoRejection({ code, path, message });
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Renders a profile as a ROS `camera_info` YAML document.
|
|
61
|
+
*
|
|
62
|
+
* The layout follows what `camera_calibration_parsers` writes, key for key and in the same order, so
|
|
63
|
+
* the file reads like one ROS produced. The projection matrix is the calibration matrix with a zero
|
|
64
|
+
* fourth column, which is what a monocular camera with no rectification has; binning and region of
|
|
65
|
+
* interest are left out, as ROS treats them as optional.
|
|
66
|
+
*
|
|
67
|
+
* Strings in the extra mapping are always double-quoted. A timestamp left plain is read as a date
|
|
68
|
+
* by YAML 1.1 readers such as PyYAML, and an id made only of digits as a number.
|
|
69
|
+
*/
|
|
70
|
+
export function serializeCameraInfoYaml(profile) {
|
|
71
|
+
const { fx, fy, cx, cy, skew } = profile.intrinsics;
|
|
72
|
+
const { model, coefficients } = rosDistortion(profile);
|
|
73
|
+
const lines = [
|
|
74
|
+
`image_width: ${profile.image.width}`,
|
|
75
|
+
`image_height: ${profile.image.height}`,
|
|
76
|
+
`camera_name: ${plainOrQuoted(profile.cameraId)}`,
|
|
77
|
+
...matrix('camera_matrix', 3, 3, [fx, skew, cx, 0, fy, cy, 0, 0, 1]),
|
|
78
|
+
`distortion_model: ${model}`,
|
|
79
|
+
...matrix('distortion_coefficients', 1, coefficients.length, coefficients),
|
|
80
|
+
...matrix('rectification_matrix', 3, 3, [1, 0, 0, 0, 1, 0, 0, 0, 1]),
|
|
81
|
+
...matrix('projection_matrix', 3, 4, [fx, skew, cx, 0, 0, fy, cy, 0, 0, 0, 1, 0]),
|
|
82
|
+
`${CAMERA_INFO_EXTENSION_KEY}:`,
|
|
83
|
+
` schema: ${quoted(profile.schema)}`,
|
|
84
|
+
` version: ${profile.version}`,
|
|
85
|
+
` profileId: ${quoted(profile.profileId)}`,
|
|
86
|
+
` calibratedAt: ${quoted(profile.calibratedAt)}`,
|
|
87
|
+
` producer: ${quoted(profile.producer)}`,
|
|
88
|
+
` undistorted: ${profile.image.undistorted}`
|
|
89
|
+
];
|
|
90
|
+
const capture = profile.capture;
|
|
91
|
+
if (capture !== undefined) {
|
|
92
|
+
lines.push(' capture:');
|
|
93
|
+
if (Object.keys(capture).length === 0)
|
|
94
|
+
lines[lines.length - 1] += ' {}';
|
|
95
|
+
appendMember(lines, 'frameRate', capture.frameRate);
|
|
96
|
+
appendMember(lines, 'facingMode', capture.facingMode);
|
|
97
|
+
appendMember(lines, 'resizeMode', capture.resizeMode);
|
|
98
|
+
appendMember(lines, 'zoom', capture.zoom);
|
|
99
|
+
appendMember(lines, 'focusMode', capture.focusMode);
|
|
100
|
+
appendMember(lines, 'focusDistance', capture.focusDistance);
|
|
101
|
+
}
|
|
102
|
+
if (profile.quality !== undefined) {
|
|
103
|
+
lines.push(' quality:');
|
|
104
|
+
appendMember(lines, 'sampleCount', profile.quality.sampleCount);
|
|
105
|
+
appendMember(lines, 'reprojectionErrorPx', profile.quality.reprojectionErrorPx);
|
|
106
|
+
}
|
|
107
|
+
if (profile.device !== undefined) {
|
|
108
|
+
lines.push(' device:');
|
|
109
|
+
if (Object.keys(profile.device).length === 0)
|
|
110
|
+
lines[lines.length - 1] += ' {}';
|
|
111
|
+
appendMember(lines, 'label', profile.device.label);
|
|
112
|
+
appendMember(lines, 'deviceId', profile.device.deviceId);
|
|
113
|
+
}
|
|
114
|
+
return `${lines.join('\n')}\n`;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Turns a ROS `camera_info` YAML document into a profile document, ready to be validated.
|
|
118
|
+
*
|
|
119
|
+
* Only the shape ROS defines is checked here -- matrix sizes, the fixed entries of the calibration
|
|
120
|
+
* matrix, a rectification that does nothing, a distortion model ROS names. Everything the profile
|
|
121
|
+
* contract says about the values themselves is left to the profile validator, so there is one
|
|
122
|
+
* place that decides whether a calibration is acceptable.
|
|
123
|
+
*/
|
|
124
|
+
export function readCameraInfoYaml(text) {
|
|
125
|
+
let parsed;
|
|
126
|
+
try {
|
|
127
|
+
parsed = parseYaml(text);
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
if (error instanceof YamlError) {
|
|
131
|
+
return { ok: false, error: { code: 'not-an-object', path: '', message: `The profile is not valid YAML. ${error.message}` } };
|
|
132
|
+
}
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
return readCameraInfoDocument(parsed);
|
|
136
|
+
}
|
|
137
|
+
/** Validate a raw ROS mapping without serializing or replacing the editable data. */
|
|
138
|
+
export function readCameraInfoDocument(parsed) {
|
|
139
|
+
try {
|
|
140
|
+
return { ok: true, document: toProfileDocument(parsed) };
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
if (error instanceof CameraInfoRejection)
|
|
144
|
+
return { ok: false, error: error.detail };
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function toProfileDocument(parsed) {
|
|
149
|
+
const root = record(parsed, '');
|
|
150
|
+
for (const key of Object.keys(root)) {
|
|
151
|
+
if (!ROOT_KEYS.has(key))
|
|
152
|
+
refuse('unexpected-field', key, 'Unknown member.');
|
|
153
|
+
}
|
|
154
|
+
readBinningAndRoi(root);
|
|
155
|
+
const width = root['image_width'];
|
|
156
|
+
const height = root['image_height'];
|
|
157
|
+
if (width === undefined)
|
|
158
|
+
refuse('missing-field', 'image_width', 'Required member is missing.');
|
|
159
|
+
if (height === undefined)
|
|
160
|
+
refuse('missing-field', 'image_height', 'Required member is missing.');
|
|
161
|
+
const k = readMatrix(root, 'camera_matrix', 3, 3);
|
|
162
|
+
expectEntries(k, 'camera_matrix', [
|
|
163
|
+
[3, 0],
|
|
164
|
+
[6, 0],
|
|
165
|
+
[7, 0],
|
|
166
|
+
[8, 1]
|
|
167
|
+
]);
|
|
168
|
+
if ('rectification_matrix' in root) {
|
|
169
|
+
const r = readMatrix(root, 'rectification_matrix', 3, 3);
|
|
170
|
+
expectEntries(r, 'rectification_matrix', [1, 0, 0, 0, 1, 0, 0, 0, 1].map((value, index) => [index, value]), 'A rectification other than identity belongs to a stereo pair, not to one camera\'s intrinsics.');
|
|
171
|
+
}
|
|
172
|
+
if ('projection_matrix' in root)
|
|
173
|
+
readMatrix(root, 'projection_matrix', 3, 4);
|
|
174
|
+
const distortion = readDistortion(root);
|
|
175
|
+
const extension = root[CAMERA_INFO_EXTENSION_KEY];
|
|
176
|
+
if (extension === undefined) {
|
|
177
|
+
refuse('missing-field', CAMERA_INFO_EXTENSION_KEY, 'The file is a ROS camera_info document without the calibration record: when it was calibrated and under which camera settings are not known.');
|
|
178
|
+
}
|
|
179
|
+
const extra = record(extension, CAMERA_INFO_EXTENSION_KEY);
|
|
180
|
+
const known = new Set(['schema', 'version', 'profileId', 'calibratedAt', 'producer', 'undistorted', 'capture', 'quality', 'device']);
|
|
181
|
+
for (const key of Object.keys(extra)) {
|
|
182
|
+
if (!known.has(key))
|
|
183
|
+
refuse('unexpected-field', `${CAMERA_INFO_EXTENSION_KEY}.${key}`, 'Unknown member.');
|
|
184
|
+
}
|
|
185
|
+
if (extra['schema'] !== CAMERA_INTRINSIC_PROFILE_SCHEMA) {
|
|
186
|
+
refuse('unsupported-schema', `${CAMERA_INFO_EXTENSION_KEY}.schema`, `Expected ${JSON.stringify(CAMERA_INTRINSIC_PROFILE_SCHEMA)}.`);
|
|
187
|
+
}
|
|
188
|
+
if (extra['version'] !== CAMERA_INTRINSIC_PROFILE_VERSION) {
|
|
189
|
+
refuse('unsupported-version', `${CAMERA_INFO_EXTENSION_KEY}.version`, `Expected ${CAMERA_INTRINSIC_PROFILE_VERSION}.`);
|
|
190
|
+
}
|
|
191
|
+
const undistorted = extra['undistorted'] ?? false;
|
|
192
|
+
return {
|
|
193
|
+
schema: CAMERA_INTRINSIC_PROFILE_SCHEMA,
|
|
194
|
+
version: CAMERA_INTRINSIC_PROFILE_VERSION,
|
|
195
|
+
profileId: extra['profileId'],
|
|
196
|
+
cameraId: root['camera_name'],
|
|
197
|
+
calibratedAt: extra['calibratedAt'],
|
|
198
|
+
producer: extra['producer'],
|
|
199
|
+
cameraModel: 'pinhole',
|
|
200
|
+
image: { width, height, undistorted },
|
|
201
|
+
intrinsics: { fx: k[0], fy: k[4], cx: k[2], cy: k[5], skew: k[1] },
|
|
202
|
+
distortion,
|
|
203
|
+
...('capture' in extra ? { capture: extra['capture'] } : {}),
|
|
204
|
+
...('quality' in extra ? { quality: extra['quality'] } : {}),
|
|
205
|
+
...('device' in extra ? { device: extra['device'] } : {})
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Maps a ROS distortion model onto the profile's.
|
|
210
|
+
*
|
|
211
|
+
* `plumb_bob` coefficients that are all zero read as no distortion. ROS has no model for "none"; a
|
|
212
|
+
* lens-free image is written as plumb_bob with five zeros, and reading it back must not invent a
|
|
213
|
+
* Brown-Conrady lens that happens to do nothing.
|
|
214
|
+
*/
|
|
215
|
+
function readDistortion(root) {
|
|
216
|
+
const rawModel = root['distortion_model'] ?? PLUMB_BOB;
|
|
217
|
+
const coefficients = readMatrix(root, 'distortion_coefficients', 1, undefined);
|
|
218
|
+
switch (rawModel) {
|
|
219
|
+
case PLUMB_BOB:
|
|
220
|
+
if (coefficients.length !== 4 && coefficients.length !== 5) {
|
|
221
|
+
refuse('invalid-distortion', 'distortion_coefficients', `plumb_bob takes 5 coefficients, not ${coefficients.length}.`);
|
|
222
|
+
}
|
|
223
|
+
return isAllZero(coefficients) ? { model: 'none', coefficients: [] } : { model: 'brown-conrady', coefficients };
|
|
224
|
+
case RATIONAL_POLYNOMIAL:
|
|
225
|
+
if (coefficients.length !== 8) {
|
|
226
|
+
refuse('invalid-distortion', 'distortion_coefficients', `rational_polynomial takes 8 coefficients, not ${coefficients.length}.`);
|
|
227
|
+
}
|
|
228
|
+
return { model: 'brown-conrady', coefficients };
|
|
229
|
+
case EQUIDISTANT:
|
|
230
|
+
if (coefficients.length !== 4) {
|
|
231
|
+
refuse('invalid-distortion', 'distortion_coefficients', `equidistant takes 4 coefficients, not ${coefficients.length}.`);
|
|
232
|
+
}
|
|
233
|
+
return { model: 'kannala-brandt', coefficients };
|
|
234
|
+
default:
|
|
235
|
+
refuse('invalid-distortion', 'distortion_model', `Expected ${PLUMB_BOB}, ${RATIONAL_POLYNOMIAL} or ${EQUIDISTANT}.`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Binning and a region of interest change which pixels the calibration describes. ROS writes both
|
|
240
|
+
* with their do-nothing values, and only those are accepted: a calibration of a binned or cropped
|
|
241
|
+
* image is a different calibration, and reading it as the full frame's would move the principal
|
|
242
|
+
* point without anyone noticing.
|
|
243
|
+
*/
|
|
244
|
+
function readBinningAndRoi(root) {
|
|
245
|
+
for (const name of ['binning_x', 'binning_y']) {
|
|
246
|
+
const value = root[name];
|
|
247
|
+
if (value !== undefined && value !== 0 && value !== 1) {
|
|
248
|
+
refuse('inconsistent-profile', name, 'A binned image is not the image the calibration describes.');
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const roi = root['roi'];
|
|
252
|
+
if (roi === undefined)
|
|
253
|
+
return;
|
|
254
|
+
const region = record(roi, 'roi');
|
|
255
|
+
const width = region['width'] ?? 0;
|
|
256
|
+
const height = region['height'] ?? 0;
|
|
257
|
+
const offsetX = region['x_offset'] ?? 0;
|
|
258
|
+
const offsetY = region['y_offset'] ?? 0;
|
|
259
|
+
const whole = width === 0 && height === 0;
|
|
260
|
+
const full = width === root['image_width'] && height === root['image_height'];
|
|
261
|
+
if (offsetX !== 0 || offsetY !== 0 || !(whole || full)) {
|
|
262
|
+
refuse('inconsistent-profile', 'roi', 'A region of interest is not the image the calibration describes.');
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function rosDistortion(profile) {
|
|
266
|
+
const coefficients = [...profile.distortion.coefficients];
|
|
267
|
+
switch (profile.distortion.model) {
|
|
268
|
+
case 'none':
|
|
269
|
+
return { model: PLUMB_BOB, coefficients: [0, 0, 0, 0, 0] };
|
|
270
|
+
case 'kannala-brandt':
|
|
271
|
+
return { model: EQUIDISTANT, coefficients };
|
|
272
|
+
case 'brown-conrady':
|
|
273
|
+
if (coefficients.length === 8)
|
|
274
|
+
return { model: RATIONAL_POLYNOMIAL, coefficients };
|
|
275
|
+
// ROS readers expect k3 to be present; a four-term Brown-Conrady lens has k3 = 0.
|
|
276
|
+
return { model: PLUMB_BOB, coefficients: coefficients.length === 4 ? [...coefficients, 0] : coefficients };
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function readMatrix(root, name, rows, cols) {
|
|
280
|
+
const value = root[name];
|
|
281
|
+
if (value === undefined)
|
|
282
|
+
refuse('missing-field', name, 'Required member is missing.');
|
|
283
|
+
const matrix = record(value, name);
|
|
284
|
+
const declaredRows = matrix['rows'];
|
|
285
|
+
const declaredCols = matrix['cols'];
|
|
286
|
+
const data = matrix['data'];
|
|
287
|
+
if (declaredRows !== rows)
|
|
288
|
+
refuse('invalid-value', `${name}.rows`, `Expected ${rows}.`);
|
|
289
|
+
if (cols !== undefined && declaredCols !== cols)
|
|
290
|
+
refuse('invalid-value', `${name}.cols`, `Expected ${cols}.`);
|
|
291
|
+
if (typeof declaredCols !== 'number' || !Number.isInteger(declaredCols) || declaredCols < 0) {
|
|
292
|
+
refuse('invalid-value', `${name}.cols`, 'Expected a column count.');
|
|
293
|
+
}
|
|
294
|
+
if (!Array.isArray(data))
|
|
295
|
+
refuse('invalid-type', `${name}.data`, 'Expected a sequence of numbers.');
|
|
296
|
+
if (data.length !== rows * declaredCols) {
|
|
297
|
+
refuse('invalid-value', `${name}.data`, `Expected ${rows * declaredCols} numbers for a ${rows}x${declaredCols} matrix, not ${data.length}.`);
|
|
298
|
+
}
|
|
299
|
+
return data.map((entry, index) => {
|
|
300
|
+
if (typeof entry !== 'number' || !Number.isFinite(entry)) {
|
|
301
|
+
refuse('invalid-type', `${name}.data[${index}]`, 'Expected a number.');
|
|
302
|
+
}
|
|
303
|
+
return entry;
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
function expectEntries(data, name, entries, message) {
|
|
307
|
+
for (const [index, expected] of entries) {
|
|
308
|
+
if (Math.abs(data[index] - expected) > MATRIX_TOLERANCE) {
|
|
309
|
+
refuse('inconsistent-profile', `${name}.data[${index}]`, message ?? `Expected ${expected}; the value read as ${data[index]}.`);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
function record(value, path) {
|
|
314
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
315
|
+
refuse('not-an-object', path, 'Expected a mapping.');
|
|
316
|
+
}
|
|
317
|
+
return value;
|
|
318
|
+
}
|
|
319
|
+
function isAllZero(values) {
|
|
320
|
+
return values.every((value) => value === 0);
|
|
321
|
+
}
|
|
322
|
+
function matrix(name, rows, cols, data) {
|
|
323
|
+
return [`${name}:`, ` rows: ${rows}`, ` cols: ${cols}`, ` data: [${data.map(number).join(', ')}]`];
|
|
324
|
+
}
|
|
325
|
+
/** Numbers as JavaScript writes them, which is the shortest text that reads back to the same value. */
|
|
326
|
+
function number(value) {
|
|
327
|
+
return Object.is(value, -0) ? '0' : String(value);
|
|
328
|
+
}
|
|
329
|
+
function quoted(text) {
|
|
330
|
+
return JSON.stringify(text);
|
|
331
|
+
}
|
|
332
|
+
/** Camera names are identifiers and read the same plain, which is how ROS writes them. */
|
|
333
|
+
function plainOrQuoted(text) {
|
|
334
|
+
return /^[A-Za-z][A-Za-z0-9._-]*$/.test(text) && !/^(?:true|false|null|yes|no|on|off|y|n)$/i.test(text) ? text : quoted(text);
|
|
335
|
+
}
|
|
336
|
+
function appendMember(lines, name, value) {
|
|
337
|
+
if (value === undefined)
|
|
338
|
+
return;
|
|
339
|
+
lines.push(` ${name}: ${typeof value === 'string' ? quoted(value) : number(value)}`);
|
|
340
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation and normalization for intrinsic calibration profiles.
|
|
3
|
+
*
|
|
4
|
+
* The validator is hand-written and pulls in no runtime dependency, which is what keeps the shipped
|
|
5
|
+
* bundle small enough that every extension needing a camera can afford to load it. The published
|
|
6
|
+
* JSON Schema in `schemas/` is the same contract written for outside readers, and a test checks the
|
|
7
|
+
* two against one set of fixtures so they cannot drift apart.
|
|
8
|
+
*
|
|
9
|
+
* Everything here is fail-closed. A document that is not understood is rejected with a reason;
|
|
10
|
+
* nothing is repaired, defaulted, or partially accepted, because a profile that is silently patched
|
|
11
|
+
* produces a projection that looks reasonable and is wrong.
|
|
12
|
+
*/
|
|
13
|
+
import type { CameraIntrinsicProfileV1, ProfileResult } from './types.js';
|
|
14
|
+
export declare const CAMERA_INTRINSIC_PROFILE_SCHEMA = "twcs/camera-intrinsics";
|
|
15
|
+
export declare const CAMERA_INTRINSIC_PROFILE_VERSION = 1;
|
|
16
|
+
/** The application-specific format this contract replaces. Read for migration, never written. */
|
|
17
|
+
export declare const LEGACY_CALIBRATION_SCHEMA = "twrmc/camera-calibration";
|
|
18
|
+
/**
|
|
19
|
+
* Reads whichever profile format a document is written in.
|
|
20
|
+
*
|
|
21
|
+
* An operator holding a file does not know, and should not have to know, which of two schemas it
|
|
22
|
+
* uses; they know they calibrated this camera once and kept the result. Dispatching on the document
|
|
23
|
+
* itself means one entry point accepts both, and the profile that comes out records where it came
|
|
24
|
+
* from in `producer`, so nothing about the conversion is hidden.
|
|
25
|
+
*
|
|
26
|
+
* Only the declared schema decides. A document that says nothing recognizable is refused by the
|
|
27
|
+
* current parser, which names what it expected.
|
|
28
|
+
*/
|
|
29
|
+
export declare function readCameraProfileDocument(input: unknown): ProfileResult;
|
|
30
|
+
/** Validates a parsed document and returns a normalized profile, or the reason it was refused. */
|
|
31
|
+
export declare function parseCameraIntrinsicProfile(input: unknown): ProfileResult;
|
|
32
|
+
/** Validates profile JSON. Text that is not JSON at all is refused like any other invalid input. */
|
|
33
|
+
export declare function parseCameraIntrinsicProfileJson(text: string): ProfileResult;
|
|
34
|
+
export declare function serializeCameraIntrinsicProfile(profile: CameraIntrinsicProfileV1): string;
|
|
35
|
+
/**
|
|
36
|
+
* Converts a `twrmc/camera-calibration` v1 document into this contract.
|
|
37
|
+
*
|
|
38
|
+
* The world pose the old format carried is deliberately dropped. It was the extrinsic of whichever
|
|
39
|
+
* calibration sample happened to be last, so treating it as a placement in a shared world frame puts
|
|
40
|
+
* a camera somewhere it has never been. Placement belongs to whoever solves it against a common
|
|
41
|
+
* reference, and a profile that simply lacks it is honest about what it knows.
|
|
42
|
+
*
|
|
43
|
+
* Quality is dropped for the same reason: the old format recorded none, and inventing a sample count
|
|
44
|
+
* or a reprojection error would turn "unknown" into a measurement.
|
|
45
|
+
*/
|
|
46
|
+
export declare function adoptLegacyCameraCalibration(input: unknown): ProfileResult;
|