@kubohiroya/turbowarp-camera-source 0.10.0 → 0.11.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 CHANGED
@@ -26,13 +26,13 @@ TurboWarp-Camera-Sourceは、MediaDevicesのカメラストリームを名前付
26
26
  次のURLをunsandboxed custom extensionとして読み込みます。
27
27
 
28
28
  ```text
29
- https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-source@0.10.0/dist/camera-source.js
29
+ https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-source@0.11.0/dist/camera-source.js
30
30
  ```
31
31
 
32
32
  npm hostでは次を使います。
33
33
 
34
34
  ```bash
35
- pnpm add @kubohiroya/turbowarp-camera-source@0.10.0
35
+ pnpm add @kubohiroya/turbowarp-camera-source@0.11.0
36
36
  ```
37
37
 
38
38
  ## Quick start
@@ -69,11 +69,12 @@ stop shared camera [pose]
69
69
  - `camera device count`: 更新済みカメラデバイス数を返します。
70
70
  - `camera device ID at [INDEX]`: 1始まりの位置でカメラdevice IDを返します。
71
71
  - `camera device label at [INDEX]`: 1始まりの位置でカメララベルを返します。
72
- - `register camera profile [PROFILE_JSON]`: 内部校正プロファイルを検証して登録します。現行の`twcs/camera-intrinsics`と、旧`twrmc/camera-calibration`のどちらの文書も受け取ります。
72
+ - `register camera profile [PROFILE_JSON]`: 内部校正プロファイルを検証して登録します。校正アプリが書き出すROSの`camera_info` YAML(`turbowarp_camera_source`の項目付き)と、`twcs/camera-intrinsics`のJSON、旧`twrmc/camera-calibration`のJSONを受け取ります。
73
73
  - `register camera profile [PROFILE_JSON] as [CAMERA_ID]`: 文書が持つcamera IDを指定したIDへ置き換えてから検証し、登録します。校正アプリで`default`として解いたプロファイルを`pose`として使う場合などに使います。camera profile errorの扱いは通常の登録ブロックと同じです。
74
74
  - `forget camera profile for [CAMERA_ID]`: 登録済みプロファイルを破棄します。
75
75
  - `camera [CAMERA_ID] is calibrated?`: プロファイルが登録されているかを返します。未登録は正常な状態です。
76
- - `camera profile JSON for [CAMERA_ID]`: 保存された文書をそのまま返します。表示や書き出し用であって、投影に使う数値ではありません。
76
+ - `camera profile JSON for [CAMERA_ID]`: 登録された文書を`twcs/camera-intrinsics`のJSONで返します。表示や保存用であって、投影に使う数値ではありません。ファイルとして渡すには`camera profile YAML`を使います。
77
+ - `camera profile YAML for [CAMERA_ID]`: 登録された文書をROSの`camera_info` YAMLで返します。ファイルへの書き出しやQRコードにはこの形を使います。標準の部分はROSやOpenCV系のツールがそのまま読み、`turbowarp_camera_source`の項目に適合判定に要る校正日時と撮影条件が入ります。
77
78
  - `camera profile error`: 直近の登録失敗のコードを返します。成功後は空文字列です。
78
79
  - `camera profile error detail`: 直近の登録失敗の位置と理由を返します。
79
80
  - `camera profile compatibility for [CAMERA_ID]`: `compatible`/`incompatible`/`undetermined`を返します。
@@ -167,6 +168,65 @@ import type {CameraFrameSource, CameraLease} from "@kubohiroya/turbowarp-camera-
167
168
 
168
169
  **「判定できない」は「適合する」とは別の答え。** 適合性は`compatible`/`incompatible`/`undetermined`の3値で、不明が`compatible`へ格上げされることはない。プロファイルが現在の構成に適合していない限り内部行列は渡さない。渡してしまえば、利用側は別の構成の数値で投影し、**もっともらしく間違った幾何**を得ることになる。
169
170
 
171
+ ### 校正ファイル
172
+
173
+ PCの外へ出る校正(ファイルやQRコード)は、ROSの`camera_info` YAMLで書く。ROSの`camera_calibration_parsers`が読み書きする形式で、OpenCV系の処理、ROS/ROS 2のドライバ、SLAMツールがそのまま読める。`camera profile YAML for [CAMERA_ID]`は登録済みのプロファイルをこの形で返し、`register camera profile`はプロファイルJSONと同じようにこれを読む。
174
+
175
+ ```yaml
176
+ image_width: 1280
177
+ image_height: 720
178
+ camera_name: stage-left
179
+ camera_matrix:
180
+ rows: 3
181
+ cols: 3
182
+ data: [940.25, 0, 639.5, 0, 939.5, 359.5, 0, 0, 1]
183
+ distortion_model: plumb_bob
184
+ distortion_coefficients:
185
+ rows: 1
186
+ cols: 5
187
+ data: [-0.32, 0.11, 0.0002, -0.0003, -0.018]
188
+ rectification_matrix:
189
+ rows: 3
190
+ cols: 3
191
+ data: [1, 0, 0, 0, 1, 0, 0, 0, 1]
192
+ projection_matrix:
193
+ rows: 3
194
+ cols: 4
195
+ data: [940.25, 0, 639.5, 0, 0, 939.5, 359.5, 0, 0, 0, 1, 0]
196
+ turbowarp_camera_source:
197
+ schema: "twcs/camera-intrinsics"
198
+ version: 1
199
+ profileId: "run-2026-09-15-a"
200
+ calibratedAt: "2026-09-15T04:05:06Z"
201
+ producer: "chessboard calibration"
202
+ undistorted: false
203
+ capture:
204
+ resizeMode: "none"
205
+ zoom: 1
206
+ focusMode: "manual"
207
+ quality:
208
+ sampleCount: 24
209
+ reprojectionErrorPx: 0.28
210
+ ```
211
+
212
+ **標準の部分はROSのキーと形そのままである。** 歪みモデルは、`brown-conrady`の5係数(4係数は`k3 = 0`を足して書く)⇔`plumb_bob`、8係数⇔`rational_polynomial`、`kannala-brandt`⇔`equidistant`と対応する。ROSには「歪みなし」のモデルが無いので、歪みの無い画像は5つの0の`plumb_bob`で書き、読むと`none`に戻る。
213
+
214
+ **ROSに置き場の無い情報は`turbowarp_camera_source`の下に入れる。** 校正日時、どの校正か、適合判定に使う撮影条件は、プロファイルがまだ使えるかを決めるのに要る。項目名はプロファイルのもので、撮影条件は`MediaTrackSettings`の名前である。ROSの読み込み処理はキーを名前で引くだけでこの項目を見ないので、ファイルはROSでもそのまま読める。この項目の無い素のROSファイルは`missing-field`で拒否する。校正日時を捏造すれば「分からない」が記録に化けるからである。
215
+
216
+ **読み込みはJSONと同じくfail closedである。** ほかのトップレベルのキー、単位行列でない平行化行列(ステレオの組のもの)、ビニングや切り出した関心領域、固定値の違う内部行列、ROSが定めていない係数の数は、該当する項目を示して拒否する。値そのものはJSONと同じ検証器を通る。読めるYAMLはyaml-cppとPyYAMLが書くもの(ブロックとフローのコレクション、引用符、コメント)で、アンカー、エイリアス、タグ、ブロックスカラー、複数文書は推測せずに拒否する。
217
+
218
+ 同じ規則を、TurboWarpの外のコード(校正アプリが書いたファイルを確かめるテストなど)のために関数として公開している。
219
+
220
+ ```ts
221
+ import {
222
+ readProfileText,
223
+ readCameraProfileDocument,
224
+ serializeCameraInfoYaml,
225
+ evaluateProfileCompatibility,
226
+ readCameraConditions
227
+ } from "@kubohiroya/turbowarp-camera-source/profile";
228
+ ```
229
+
170
230
  ### ブラウザストレージ
171
231
 
172
232
  プロファイルはブラウザ内に保持でき、次の作業や別ウィンドウでファイルを読み直さずに済む。`save camera profile for [CAMERA_ID] to browser storage`は登録済みプロファイルをIndexedDB(データベース`kubohiroya-camera-source`、object store`camera-profiles`、キーは`profileId`)へ書き込み、BroadcastChannel`kubohiroya-camera-source:camera-profiles`で保存を知らせる。`stored camera profiles generation`は、このウィンドウでも同じoriginの別ウィンドウでも保存のたびに増えるので、別ウィンドウの校正アプリを待つ作品はこの整数だけを見て、動いたら復元すればよい。
@@ -185,6 +245,8 @@ if <(stored camera profile result for [pose]) = [restored]> then
185
245
 
186
246
  ## 互換性
187
247
 
248
+ 0.11.0では校正ファイルをROSの`camera_info` YAMLで読み書きするようにした。`camera profile YAML`を追加し、`register camera profile`はYAMLも受け取り、処理だけを持つ関数を`./profile`で公開した。既存のブロックとcapabilityのメンバーは変えていない。
249
+
188
250
  0.10.0では校正プロファイルのブラウザストレージと`register camera profile as`を追加した。既存のブロックとcapabilityのメンバーは変えていない。
189
251
 
190
252
  未リリースの変更は破壊的である。`CameraFrameSource.mirrored`は`previewFlip`へ置き換えた。軸を名指しでき、かつ「描画の話であって画素の話ではない」と言えるためである。previewブロックの`MIRRORED`引数は`PREVIEW_FLIP`へ置き換え、booleanはもう読まない。`acquireCamera`は`previewFlip`を受け取り、`mirrored`は受け付けない。frame sourceのinterfaceを手書きで持っている利用側は、公開した`./runtime`のimportへ移ること。そうしていればこの変更はビルド時に分かった。
package/README.md CHANGED
@@ -30,13 +30,13 @@ or select separate cameras for separate roles.
30
30
  Load this URL as an unsandboxed custom extension:
31
31
 
32
32
  ```text
33
- https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-source@0.10.0/dist/camera-source.js
33
+ https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-source@0.11.0/dist/camera-source.js
34
34
  ```
35
35
 
36
36
  For npm hosts:
37
37
 
38
38
  ```bash
39
- pnpm add @kubohiroya/turbowarp-camera-source@0.10.0
39
+ pnpm add @kubohiroya/turbowarp-camera-source@0.11.0
40
40
  ```
41
41
 
42
42
  ## Quick Start
@@ -210,7 +210,7 @@ Returns the one-based camera device label at the requested index when the browse
210
210
 
211
211
  ### `register camera profile [PROFILE_JSON]`
212
212
 
213
- Validates a twcs/camera-intrinsics version 1 document and stores it against the camera it names. Nothing is stored unless the whole document passes, and the profile in force for that camera is replaced.
213
+ Validates a calibration and stores it against the camera it names. Accepts a ROS camera_info YAML file carrying the turbowarp_camera_source mapping, as the calibration app writes it, as well as twcs/camera-intrinsics version 1 JSON and the legacy twrmc/camera-calibration JSON. Nothing is stored unless the whole document passes, and the profile in force for that camera is replaced.
214
214
 
215
215
  | Property | Value |
216
216
  |---|---|
@@ -251,7 +251,7 @@ Reports whether a calibration profile is stored for the camera. An uncalibrated
251
251
 
252
252
  ### `camera profile JSON for [CAMERA_ID]`
253
253
 
254
- Returns the stored profile as JSON, or an empty string when the camera has none.
254
+ Returns the stored profile as twcs/camera-intrinsics JSON, or an empty string when the camera has none. For a file to hand to another machine or tool, use camera profile YAML.
255
255
 
256
256
  | Property | Value |
257
257
  |---|---|
@@ -259,6 +259,16 @@ Returns the stored profile as JSON, or an empty string when the camera has none.
259
259
  | Opcode | `cameraProfileJson` |
260
260
  | `CAMERA_ID` | String, default: `default` |
261
261
 
262
+ ### `camera profile YAML for [CAMERA_ID]`
263
+
264
+ Returns the stored profile as a ROS camera_info YAML document, or an empty string when the camera has none. This is the form to write to a file or show as a QR code: ROS and OpenCV-based tools read the standard part as it is, and the turbowarp_camera_source mapping carries the calibration time and camera settings compatibility needs.
265
+
266
+ | Property | Value |
267
+ |---|---|
268
+ | Type | Reporter |
269
+ | Opcode | `cameraProfileYaml` |
270
+ | `CAMERA_ID` | String, default: `default` |
271
+
262
272
  ### `camera profile error`
263
273
 
264
274
  Returns the code of the last rejected profile document, or an empty string when the last one was accepted.
@@ -481,6 +491,82 @@ own repository and fails in a browser instead.
481
491
 
482
492
  **"Cannot tell" is a distinct answer from "fits".** Compatibility is `compatible`, `incompatible` or `undetermined`, and unknown never resolves upward. Intrinsics are withheld unless the profile actually fits the camera as configured now: handing them over regardless would let a consumer project with numbers from a different configuration and get plausible, wrong geometry back.
483
493
 
494
+ ### Calibration files
495
+
496
+ A calibration that leaves the PC — a file, or a QR code — is a ROS `camera_info` YAML document, the
497
+ format ROS's `camera_calibration_parsers` reads and writes and that OpenCV-based pipelines, ROS and
498
+ ROS 2 drivers and SLAM tools load as it is. `camera profile YAML for [CAMERA_ID]` renders the
499
+ registered profile that way, and `register camera profile` reads it back as well as profile JSON.
500
+
501
+ ```yaml
502
+ image_width: 1280
503
+ image_height: 720
504
+ camera_name: stage-left
505
+ camera_matrix:
506
+ rows: 3
507
+ cols: 3
508
+ data: [940.25, 0, 639.5, 0, 939.5, 359.5, 0, 0, 1]
509
+ distortion_model: plumb_bob
510
+ distortion_coefficients:
511
+ rows: 1
512
+ cols: 5
513
+ data: [-0.32, 0.11, 0.0002, -0.0003, -0.018]
514
+ rectification_matrix:
515
+ rows: 3
516
+ cols: 3
517
+ data: [1, 0, 0, 0, 1, 0, 0, 0, 1]
518
+ projection_matrix:
519
+ rows: 3
520
+ cols: 4
521
+ data: [940.25, 0, 639.5, 0, 0, 939.5, 359.5, 0, 0, 0, 1, 0]
522
+ turbowarp_camera_source:
523
+ schema: "twcs/camera-intrinsics"
524
+ version: 1
525
+ profileId: "run-2026-09-15-a"
526
+ calibratedAt: "2026-09-15T04:05:06Z"
527
+ producer: "chessboard calibration"
528
+ undistorted: false
529
+ capture:
530
+ resizeMode: "none"
531
+ zoom: 1
532
+ focusMode: "manual"
533
+ quality:
534
+ sampleCount: 24
535
+ reprojectionErrorPx: 0.28
536
+ ```
537
+
538
+ **The standard part is ROS's, key for key.** Distortion models map as `brown-conrady` with five
539
+ coefficients (four are written with `k3 = 0`) ⇔ `plumb_bob`, eight ⇔ `rational_polynomial`, and
540
+ `kannala-brandt` ⇔ `equidistant`. A lens-free image is `plumb_bob` with five zeros, since ROS has no
541
+ model for none, and reads back as `none`.
542
+
543
+ **What ROS has no place for travels under `turbowarp_camera_source`.** When the camera was
544
+ calibrated, which run it was, and the capture settings compatibility is decided on are required to
545
+ tell whether a profile still fits; their member names are the profile's, and the capture members
546
+ are `MediaTrackSettings` names. ROS's reader looks keys up by name and ignores this one, so the file
547
+ still loads in ROS. A plain ROS file without it is refused with `missing-field`: inventing a
548
+ calibration time would turn "unknown" into a record.
549
+
550
+ **Reading fails closed, like JSON.** Other top-level keys, a rectification other than identity (a
551
+ stereo pair's), binning or a cropped region of interest, a calibration matrix whose fixed entries are
552
+ wrong, and a coefficient count ROS does not define are refused with the member that failed. The
553
+ values themselves then go through the same validator as JSON. The reader takes the YAML that
554
+ yaml-cpp and PyYAML write — block and flow collections, quotes, comments — and refuses anchors,
555
+ aliases, tags, block scalars and multiple documents rather than guessing.
556
+
557
+ The same rules are published as plain functions for code outside TurboWarp, such as a test that checks
558
+ a file a calibration app wrote:
559
+
560
+ ```ts
561
+ import {
562
+ readProfileText,
563
+ readCameraProfileDocument,
564
+ serializeCameraInfoYaml,
565
+ evaluateProfileCompatibility,
566
+ readCameraConditions
567
+ } from "@kubohiroya/turbowarp-camera-source/profile";
568
+ ```
569
+
484
570
  ### Browser storage
485
571
 
486
572
  A profile can be kept in the browser so the next session, or another window, does not need the file
@@ -513,6 +599,10 @@ solved under `default` in a calibration app can be registered as `pose` in the a
513
599
 
514
600
  ## Compatibility
515
601
 
602
+ Version 0.11.0 writes and reads calibration files as ROS `camera_info` YAML: `camera profile YAML`
603
+ is new, `register camera profile` also accepts YAML, and the pure functions are published under
604
+ `./profile`. No existing block or capability member changes.
605
+
516
606
  Version 0.10.0 adds browser storage for calibration profiles and `register camera profile as`. No
517
607
  existing block or capability member changes.
518
608
 
@@ -0,0 +1,32 @@
1
+ import type { CameraIntrinsicProfileV1, ProfileError } from './types.js';
2
+ /** The top-level key holding the members ROS has no place for. */
3
+ export declare const CAMERA_INFO_EXTENSION_KEY = "turbowarp_camera_source";
4
+ export type CameraInfoReadResult = {
5
+ readonly ok: true;
6
+ readonly document: Record<string, unknown>;
7
+ } | {
8
+ readonly ok: false;
9
+ readonly error: ProfileError;
10
+ };
11
+ /**
12
+ * Renders a profile as a ROS `camera_info` YAML document.
13
+ *
14
+ * The layout follows what `camera_calibration_parsers` writes, key for key and in the same order, so
15
+ * the file reads like one ROS produced. The projection matrix is the calibration matrix with a zero
16
+ * fourth column, which is what a monocular camera with no rectification has; binning and region of
17
+ * interest are left out, as ROS treats them as optional.
18
+ *
19
+ * Strings in the extra mapping are always double-quoted. A timestamp left plain is read as a date
20
+ * by YAML 1.1 readers such as PyYAML, and an id made only of digits as a number.
21
+ */
22
+ export declare function serializeCameraInfoYaml(profile: CameraIntrinsicProfileV1): string;
23
+ /**
24
+ * Turns a ROS `camera_info` YAML document into a profile document, ready to be validated.
25
+ *
26
+ * Only the shape ROS defines is checked here -- matrix sizes, the fixed entries of the calibration
27
+ * matrix, a rectification that does nothing, a distortion model ROS names. Everything the profile
28
+ * contract says about the values themselves is left to the profile validator, so there is one
29
+ * place that decides whether a calibration is acceptable.
30
+ */
31
+ export declare function readCameraInfoYaml(text: string): CameraInfoReadResult;
32
+ //# sourceMappingURL=camera-info.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"camera-info.d.ts","sourceRoot":"","sources":["../../src/calibration/camera-info.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAC,wBAAwB,EAAmB,YAAY,EAAC,MAAM,YAAY,CAAC;AAGxF,kEAAkE;AAClE,eAAO,MAAM,yBAAyB,4BAA4B,CAAC;AA+BnE,MAAM,MAAM,oBAAoB,GAC5B;IAAC,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAC,GAC/D;IAAC,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAA;CAAC,CAAC;AAYvD;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,wBAAwB,GAAG,MAAM,CA2CjF;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,oBAAoB,CAgBrE"}
@@ -0,0 +1,336 @@
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
+ constructor(detail) {
51
+ super(detail.message);
52
+ this.detail = detail;
53
+ }
54
+ }
55
+ function refuse(code, path, message) {
56
+ throw new CameraInfoRejection({ code, path, message });
57
+ }
58
+ /**
59
+ * Renders a profile as a ROS `camera_info` YAML document.
60
+ *
61
+ * The layout follows what `camera_calibration_parsers` writes, key for key and in the same order, so
62
+ * the file reads like one ROS produced. The projection matrix is the calibration matrix with a zero
63
+ * fourth column, which is what a monocular camera with no rectification has; binning and region of
64
+ * interest are left out, as ROS treats them as optional.
65
+ *
66
+ * Strings in the extra mapping are always double-quoted. A timestamp left plain is read as a date
67
+ * by YAML 1.1 readers such as PyYAML, and an id made only of digits as a number.
68
+ */
69
+ export function serializeCameraInfoYaml(profile) {
70
+ const { fx, fy, cx, cy, skew } = profile.intrinsics;
71
+ const { model, coefficients } = rosDistortion(profile);
72
+ const lines = [
73
+ `image_width: ${profile.image.width}`,
74
+ `image_height: ${profile.image.height}`,
75
+ `camera_name: ${plainOrQuoted(profile.cameraId)}`,
76
+ ...matrix('camera_matrix', 3, 3, [fx, skew, cx, 0, fy, cy, 0, 0, 1]),
77
+ `distortion_model: ${model}`,
78
+ ...matrix('distortion_coefficients', 1, coefficients.length, coefficients),
79
+ ...matrix('rectification_matrix', 3, 3, [1, 0, 0, 0, 1, 0, 0, 0, 1]),
80
+ ...matrix('projection_matrix', 3, 4, [fx, skew, cx, 0, 0, fy, cy, 0, 0, 0, 1, 0]),
81
+ `${CAMERA_INFO_EXTENSION_KEY}:`,
82
+ ` schema: ${quoted(profile.schema)}`,
83
+ ` version: ${profile.version}`,
84
+ ` profileId: ${quoted(profile.profileId)}`,
85
+ ` calibratedAt: ${quoted(profile.calibratedAt)}`,
86
+ ` producer: ${quoted(profile.producer)}`,
87
+ ` undistorted: ${profile.image.undistorted}`
88
+ ];
89
+ const capture = profile.capture;
90
+ if (capture !== undefined) {
91
+ lines.push(' capture:');
92
+ if (Object.keys(capture).length === 0)
93
+ lines[lines.length - 1] += ' {}';
94
+ appendMember(lines, 'frameRate', capture.frameRate);
95
+ appendMember(lines, 'facingMode', capture.facingMode);
96
+ appendMember(lines, 'resizeMode', capture.resizeMode);
97
+ appendMember(lines, 'zoom', capture.zoom);
98
+ appendMember(lines, 'focusMode', capture.focusMode);
99
+ appendMember(lines, 'focusDistance', capture.focusDistance);
100
+ }
101
+ if (profile.quality !== undefined) {
102
+ lines.push(' quality:');
103
+ appendMember(lines, 'sampleCount', profile.quality.sampleCount);
104
+ appendMember(lines, 'reprojectionErrorPx', profile.quality.reprojectionErrorPx);
105
+ }
106
+ if (profile.device !== undefined) {
107
+ lines.push(' device:');
108
+ if (Object.keys(profile.device).length === 0)
109
+ lines[lines.length - 1] += ' {}';
110
+ appendMember(lines, 'label', profile.device.label);
111
+ appendMember(lines, 'deviceId', profile.device.deviceId);
112
+ }
113
+ return `${lines.join('\n')}\n`;
114
+ }
115
+ /**
116
+ * Turns a ROS `camera_info` YAML document into a profile document, ready to be validated.
117
+ *
118
+ * Only the shape ROS defines is checked here -- matrix sizes, the fixed entries of the calibration
119
+ * matrix, a rectification that does nothing, a distortion model ROS names. Everything the profile
120
+ * contract says about the values themselves is left to the profile validator, so there is one
121
+ * place that decides whether a calibration is acceptable.
122
+ */
123
+ export function readCameraInfoYaml(text) {
124
+ let parsed;
125
+ try {
126
+ parsed = parseYaml(text);
127
+ }
128
+ catch (error) {
129
+ if (error instanceof YamlError) {
130
+ return { ok: false, error: { code: 'not-an-object', path: '', message: `The profile is not valid YAML. ${error.message}` } };
131
+ }
132
+ throw error;
133
+ }
134
+ try {
135
+ return { ok: true, document: toProfileDocument(parsed) };
136
+ }
137
+ catch (error) {
138
+ if (error instanceof CameraInfoRejection)
139
+ return { ok: false, error: error.detail };
140
+ throw error;
141
+ }
142
+ }
143
+ function toProfileDocument(parsed) {
144
+ const root = record(parsed, '');
145
+ for (const key of Object.keys(root)) {
146
+ if (!ROOT_KEYS.has(key))
147
+ refuse('unexpected-field', key, 'Unknown member.');
148
+ }
149
+ readBinningAndRoi(root);
150
+ const width = root['image_width'];
151
+ const height = root['image_height'];
152
+ if (width === undefined)
153
+ refuse('missing-field', 'image_width', 'Required member is missing.');
154
+ if (height === undefined)
155
+ refuse('missing-field', 'image_height', 'Required member is missing.');
156
+ const k = readMatrix(root, 'camera_matrix', 3, 3);
157
+ expectEntries(k, 'camera_matrix', [
158
+ [3, 0],
159
+ [6, 0],
160
+ [7, 0],
161
+ [8, 1]
162
+ ]);
163
+ if ('rectification_matrix' in root) {
164
+ const r = readMatrix(root, 'rectification_matrix', 3, 3);
165
+ 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.');
166
+ }
167
+ if ('projection_matrix' in root)
168
+ readMatrix(root, 'projection_matrix', 3, 4);
169
+ const distortion = readDistortion(root);
170
+ const extension = root[CAMERA_INFO_EXTENSION_KEY];
171
+ if (extension === undefined) {
172
+ 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.');
173
+ }
174
+ const extra = record(extension, CAMERA_INFO_EXTENSION_KEY);
175
+ const known = new Set(['schema', 'version', 'profileId', 'calibratedAt', 'producer', 'undistorted', 'capture', 'quality', 'device']);
176
+ for (const key of Object.keys(extra)) {
177
+ if (!known.has(key))
178
+ refuse('unexpected-field', `${CAMERA_INFO_EXTENSION_KEY}.${key}`, 'Unknown member.');
179
+ }
180
+ if (extra['schema'] !== CAMERA_INTRINSIC_PROFILE_SCHEMA) {
181
+ refuse('unsupported-schema', `${CAMERA_INFO_EXTENSION_KEY}.schema`, `Expected ${JSON.stringify(CAMERA_INTRINSIC_PROFILE_SCHEMA)}.`);
182
+ }
183
+ if (extra['version'] !== CAMERA_INTRINSIC_PROFILE_VERSION) {
184
+ refuse('unsupported-version', `${CAMERA_INFO_EXTENSION_KEY}.version`, `Expected ${CAMERA_INTRINSIC_PROFILE_VERSION}.`);
185
+ }
186
+ const undistorted = extra['undistorted'] ?? false;
187
+ return {
188
+ schema: CAMERA_INTRINSIC_PROFILE_SCHEMA,
189
+ version: CAMERA_INTRINSIC_PROFILE_VERSION,
190
+ profileId: extra['profileId'],
191
+ cameraId: root['camera_name'],
192
+ calibratedAt: extra['calibratedAt'],
193
+ producer: extra['producer'],
194
+ cameraModel: 'pinhole',
195
+ image: { width, height, undistorted },
196
+ intrinsics: { fx: k[0], fy: k[4], cx: k[2], cy: k[5], skew: k[1] },
197
+ distortion,
198
+ ...('capture' in extra ? { capture: extra['capture'] } : {}),
199
+ ...('quality' in extra ? { quality: extra['quality'] } : {}),
200
+ ...('device' in extra ? { device: extra['device'] } : {})
201
+ };
202
+ }
203
+ /**
204
+ * Maps a ROS distortion model onto the profile's.
205
+ *
206
+ * `plumb_bob` coefficients that are all zero read as no distortion. ROS has no model for "none"; a
207
+ * lens-free image is written as plumb_bob with five zeros, and reading it back must not invent a
208
+ * Brown-Conrady lens that happens to do nothing.
209
+ */
210
+ function readDistortion(root) {
211
+ const rawModel = root['distortion_model'] ?? PLUMB_BOB;
212
+ const coefficients = readMatrix(root, 'distortion_coefficients', 1, undefined);
213
+ switch (rawModel) {
214
+ case PLUMB_BOB:
215
+ if (coefficients.length !== 4 && coefficients.length !== 5) {
216
+ refuse('invalid-distortion', 'distortion_coefficients', `plumb_bob takes 5 coefficients, not ${coefficients.length}.`);
217
+ }
218
+ return isAllZero(coefficients) ? { model: 'none', coefficients: [] } : { model: 'brown-conrady', coefficients };
219
+ case RATIONAL_POLYNOMIAL:
220
+ if (coefficients.length !== 8) {
221
+ refuse('invalid-distortion', 'distortion_coefficients', `rational_polynomial takes 8 coefficients, not ${coefficients.length}.`);
222
+ }
223
+ return { model: 'brown-conrady', coefficients };
224
+ case EQUIDISTANT:
225
+ if (coefficients.length !== 4) {
226
+ refuse('invalid-distortion', 'distortion_coefficients', `equidistant takes 4 coefficients, not ${coefficients.length}.`);
227
+ }
228
+ return { model: 'kannala-brandt', coefficients };
229
+ default:
230
+ refuse('invalid-distortion', 'distortion_model', `Expected ${PLUMB_BOB}, ${RATIONAL_POLYNOMIAL} or ${EQUIDISTANT}.`);
231
+ }
232
+ }
233
+ /**
234
+ * Binning and a region of interest change which pixels the calibration describes. ROS writes both
235
+ * with their do-nothing values, and only those are accepted: a calibration of a binned or cropped
236
+ * image is a different calibration, and reading it as the full frame's would move the principal
237
+ * point without anyone noticing.
238
+ */
239
+ function readBinningAndRoi(root) {
240
+ for (const name of ['binning_x', 'binning_y']) {
241
+ const value = root[name];
242
+ if (value !== undefined && value !== 0 && value !== 1) {
243
+ refuse('inconsistent-profile', name, 'A binned image is not the image the calibration describes.');
244
+ }
245
+ }
246
+ const roi = root['roi'];
247
+ if (roi === undefined)
248
+ return;
249
+ const region = record(roi, 'roi');
250
+ const width = region['width'] ?? 0;
251
+ const height = region['height'] ?? 0;
252
+ const offsetX = region['x_offset'] ?? 0;
253
+ const offsetY = region['y_offset'] ?? 0;
254
+ const whole = width === 0 && height === 0;
255
+ const full = width === root['image_width'] && height === root['image_height'];
256
+ if (offsetX !== 0 || offsetY !== 0 || !(whole || full)) {
257
+ refuse('inconsistent-profile', 'roi', 'A region of interest is not the image the calibration describes.');
258
+ }
259
+ }
260
+ function rosDistortion(profile) {
261
+ const coefficients = [...profile.distortion.coefficients];
262
+ switch (profile.distortion.model) {
263
+ case 'none':
264
+ return { model: PLUMB_BOB, coefficients: [0, 0, 0, 0, 0] };
265
+ case 'kannala-brandt':
266
+ return { model: EQUIDISTANT, coefficients };
267
+ case 'brown-conrady':
268
+ if (coefficients.length === 8)
269
+ return { model: RATIONAL_POLYNOMIAL, coefficients };
270
+ // ROS readers expect k3 to be present; a four-term Brown-Conrady lens has k3 = 0.
271
+ return { model: PLUMB_BOB, coefficients: coefficients.length === 4 ? [...coefficients, 0] : coefficients };
272
+ }
273
+ }
274
+ function readMatrix(root, name, rows, cols) {
275
+ const value = root[name];
276
+ if (value === undefined)
277
+ refuse('missing-field', name, 'Required member is missing.');
278
+ const matrix = record(value, name);
279
+ const declaredRows = matrix['rows'];
280
+ const declaredCols = matrix['cols'];
281
+ const data = matrix['data'];
282
+ if (declaredRows !== rows)
283
+ refuse('invalid-value', `${name}.rows`, `Expected ${rows}.`);
284
+ if (cols !== undefined && declaredCols !== cols)
285
+ refuse('invalid-value', `${name}.cols`, `Expected ${cols}.`);
286
+ if (typeof declaredCols !== 'number' || !Number.isInteger(declaredCols) || declaredCols < 0) {
287
+ refuse('invalid-value', `${name}.cols`, 'Expected a column count.');
288
+ }
289
+ if (!Array.isArray(data))
290
+ refuse('invalid-type', `${name}.data`, 'Expected a sequence of numbers.');
291
+ if (data.length !== rows * declaredCols) {
292
+ refuse('invalid-value', `${name}.data`, `Expected ${rows * declaredCols} numbers for a ${rows}x${declaredCols} matrix, not ${data.length}.`);
293
+ }
294
+ return data.map((entry, index) => {
295
+ if (typeof entry !== 'number' || !Number.isFinite(entry)) {
296
+ refuse('invalid-type', `${name}.data[${index}]`, 'Expected a number.');
297
+ }
298
+ return entry;
299
+ });
300
+ }
301
+ function expectEntries(data, name, entries, message) {
302
+ for (const [index, expected] of entries) {
303
+ if (Math.abs(data[index] - expected) > MATRIX_TOLERANCE) {
304
+ refuse('inconsistent-profile', `${name}.data[${index}]`, message ?? `Expected ${expected}; the value read as ${data[index]}.`);
305
+ }
306
+ }
307
+ }
308
+ function record(value, path) {
309
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
310
+ refuse('not-an-object', path, 'Expected a mapping.');
311
+ }
312
+ return value;
313
+ }
314
+ function isAllZero(values) {
315
+ return values.every((value) => value === 0);
316
+ }
317
+ function matrix(name, rows, cols, data) {
318
+ return [`${name}:`, ` rows: ${rows}`, ` cols: ${cols}`, ` data: [${data.map(number).join(', ')}]`];
319
+ }
320
+ /** Numbers as JavaScript writes them, which is the shortest text that reads back to the same value. */
321
+ function number(value) {
322
+ return Object.is(value, -0) ? '0' : String(value);
323
+ }
324
+ function quoted(text) {
325
+ return JSON.stringify(text);
326
+ }
327
+ /** Camera names are identifiers and read the same plain, which is how ROS writes them. */
328
+ function plainOrQuoted(text) {
329
+ 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);
330
+ }
331
+ function appendMember(lines, name, value) {
332
+ if (value === undefined)
333
+ return;
334
+ lines.push(` ${name}: ${typeof value === 'string' ? quoted(value) : number(value)}`);
335
+ }
336
+ //# sourceMappingURL=camera-info.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"camera-info.js","sourceRoot":"","sources":["../../src/calibration/camera-info.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAC,+BAA+B,EAAE,gCAAgC,EAAC,MAAM,cAAc,CAAC;AAE/F,OAAO,EAAC,SAAS,EAAE,SAAS,EAAiB,MAAM,WAAW,CAAC;AAE/D,kEAAkE;AA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