@kubohiroya/turbowarp-camera-calibration 0.12.0 → 0.13.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 +3 -2
- package/README.md +3 -2
- package/dist/camera-calibration.js +38 -1
- package/docs/index.html +1 -1
- package/package.json +1 -1
- package/src/calibration/camera-source.ts +37 -0
- package/src/calibration/controller.ts +26 -2
package/README.ja.md
CHANGED
|
@@ -101,7 +101,7 @@ bundleは約11 MBあります。
|
|
|
101
101
|
検証済みのversionをexact pinします。
|
|
102
102
|
|
|
103
103
|
```bash
|
|
104
|
-
pnpm add --save-exact @kubohiroya/turbowarp-camera-calibration@0.
|
|
104
|
+
pnpm add --save-exact @kubohiroya/turbowarp-camera-calibration@0.13.0
|
|
105
105
|
```
|
|
106
106
|
|
|
107
107
|
standalone bundle:
|
|
@@ -113,7 +113,7 @@ node_modules/@kubohiroya/turbowarp-camera-calibration/dist/camera-calibration.js
|
|
|
113
113
|
version固定CDN URL:
|
|
114
114
|
|
|
115
115
|
```text
|
|
116
|
-
https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-calibration@0.
|
|
116
|
+
https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-calibration@0.13.0/dist/camera-calibration.js
|
|
117
117
|
```
|
|
118
118
|
|
|
119
119
|
## クイックスタート
|
|
@@ -211,6 +211,7 @@ block referenceは
|
|
|
211
211
|
| 校正を実行していない | 状態reporterは`idle`、プロファイルreporterは空文字列を返します |
|
|
212
212
|
| 板が見つからない、ぶれている、既存サンプルと似すぎている | 固有のエラーコードで却下し、セッションはready のままです |
|
|
213
213
|
| セッション中に解像度・device・左右反転が変わった | `resolution-mismatch` または `capture-condition-mismatch` |
|
|
214
|
+
| 解くまでの間にリサイズ・ズーム・フォーカス・カメラが変わった | `capture-condition-mismatch`。camera-source がこのカメラに合わないと判定するプロファイルになるため、`solved` ではなく `error` で終わる |
|
|
214
215
|
| 再投影誤差が上限を超えた | `reprojection-too-high`。プロファイルは保存せず、サンプルを追加できます |
|
|
215
216
|
| 別のカメラ、または別の撮影サイズのプロファイル | 状態を変更する前に`calibration-not-applicable`で拒否します |
|
|
216
217
|
| solve成功 | ただちにカメラのleaseを解放します |
|
package/README.md
CHANGED
|
@@ -102,7 +102,7 @@ therefore about 11 MB.
|
|
|
102
102
|
Install an exact version that you have reviewed:
|
|
103
103
|
|
|
104
104
|
```bash
|
|
105
|
-
pnpm add --save-exact @kubohiroya/turbowarp-camera-calibration@0.
|
|
105
|
+
pnpm add --save-exact @kubohiroya/turbowarp-camera-calibration@0.13.0
|
|
106
106
|
```
|
|
107
107
|
|
|
108
108
|
Load the standalone bundle from:
|
|
@@ -114,7 +114,7 @@ node_modules/@kubohiroya/turbowarp-camera-calibration/dist/camera-calibration.js
|
|
|
114
114
|
A version-pinned CDN URL is:
|
|
115
115
|
|
|
116
116
|
```text
|
|
117
|
-
https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-calibration@0.
|
|
117
|
+
https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-calibration@0.13.0/dist/camera-calibration.js
|
|
118
118
|
```
|
|
119
119
|
|
|
120
120
|
## Quick start
|
|
@@ -496,6 +496,7 @@ Returns the last measured board pose as JSON, or an empty string when none was m
|
|
|
496
496
|
| Camera calibration has not run | The state reporter returns `idle` and the profile reporter returns an empty string |
|
|
497
497
|
| Board not found, blurred, or too similar to a kept view | The sample is refused with its own error code and the session stays ready |
|
|
498
498
|
| Resolution, device, or mirroring changes mid-session | `resolution-mismatch` or `capture-condition-mismatch` |
|
|
499
|
+
| Resize mode, zoom, focus, or the camera changes before the solve | `capture-condition-mismatch`; the session ends in `error` rather than `solved`, because Camera Source would judge the profile not to fit this camera |
|
|
499
500
|
| Reprojection error exceeds the session limit | `reprojection-too-high`; no profile is stored and more samples can be added |
|
|
500
501
|
| Profile belongs to another camera or another capture size | `calibration-not-applicable`, rejected before any state changes |
|
|
501
502
|
| Solve succeeds | The camera lease is released immediately |
|
|
@@ -497,6 +497,35 @@
|
|
|
497
497
|
device
|
|
498
498
|
};
|
|
499
499
|
}
|
|
500
|
+
/**
|
|
501
|
+
* What changed in the camera's optics since a session began, or undefined when nothing did.
|
|
502
|
+
*
|
|
503
|
+
* The members are the ones Camera Source decides a profile's fit on -- resize mode, zoom, focus
|
|
504
|
+
* mode and focus distance, compared with its tolerances, and the device label. A difference in
|
|
505
|
+
* any of them would make the profile being solved `incompatible` with this camera the moment it
|
|
506
|
+
* was registered; conditions that could be read at the start and cannot be read now would make it
|
|
507
|
+
* `undetermined`. Either way the views were not all taken under the conditions the profile is
|
|
508
|
+
* about to claim, so the session is not worth ending as solved.
|
|
509
|
+
*
|
|
510
|
+
* Frame rate, facing mode and the device id are left out for the reason Camera Source leaves them
|
|
511
|
+
* out: none of them changes how the lens projects.
|
|
512
|
+
*/
|
|
513
|
+
function conditionsDrift(recorded, current) {
|
|
514
|
+
if (!current) return "the camera no longer reports how it is configured";
|
|
515
|
+
const changed = [];
|
|
516
|
+
const text = (name, left, right) => {
|
|
517
|
+
if (left !== right) changed.push(`${name} ${left ?? "not reported"} -> ${right ?? "not reported"}`);
|
|
518
|
+
};
|
|
519
|
+
const number = (name, left, right) => {
|
|
520
|
+
if (!(left === void 0 || right === void 0 ? left === right : Math.abs(left - right) <= 1e-6)) changed.push(`${name} ${left ?? "not reported"} -> ${right ?? "not reported"}`);
|
|
521
|
+
};
|
|
522
|
+
text("resize mode", recorded.capture.resizeMode, current.capture.resizeMode);
|
|
523
|
+
number("zoom", recorded.capture.zoom, current.capture.zoom);
|
|
524
|
+
text("focus mode", recorded.capture.focusMode, current.capture.focusMode);
|
|
525
|
+
number("focus distance", recorded.capture.focusDistance, current.capture.focusDistance);
|
|
526
|
+
if (recorded.device.label !== void 0 && current.device.label !== void 0) text("device", recorded.device.label, current.device.label);
|
|
527
|
+
return changed.length === 0 ? void 0 : changed.join(", ");
|
|
528
|
+
}
|
|
500
529
|
function requireProfileRegistry(runtime) {
|
|
501
530
|
if (!readCameraSourceRuntime(runtime)) throw new CameraSourceError("dependency-missing", "TurboWarp Camera Source is not loaded, so no calibration profile registry exists.");
|
|
502
531
|
const capability = readCameraSourceCapability(runtime);
|
|
@@ -1262,7 +1291,7 @@
|
|
|
1262
1291
|
if (this.samples.length === this.solvedFrom) return Promise.resolve();
|
|
1263
1292
|
this.solvedFrom = this.samples.length;
|
|
1264
1293
|
const solving = this.automaticSolve(operation).catch(() => {
|
|
1265
|
-
this.guide("keep-going");
|
|
1294
|
+
if (this.calibrationState !== "error") this.guide("keep-going");
|
|
1266
1295
|
});
|
|
1267
1296
|
this.solving = solving;
|
|
1268
1297
|
const clear = () => {
|
|
@@ -1670,6 +1699,14 @@
|
|
|
1670
1699
|
* it.
|
|
1671
1700
|
*/
|
|
1672
1701
|
async finishSolve(session, lease, solution) {
|
|
1702
|
+
if (session.conditions) {
|
|
1703
|
+
const drift = conditionsDrift(session.conditions, captureConditionsOf(this.runtime, this.cameraId));
|
|
1704
|
+
if (drift !== void 0) {
|
|
1705
|
+
this.stopAutomatic();
|
|
1706
|
+
await this.releaseSession();
|
|
1707
|
+
this.fail("capture-condition-mismatch", /* @__PURE__ */ new Error(`The camera settings changed during the calibration (${drift}). Restart the calibration for camera ${this.cameraId}.`));
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1673
1710
|
const sampleCount = this.samples.length;
|
|
1674
1711
|
let profile;
|
|
1675
1712
|
try {
|
package/docs/index.html
CHANGED
|
@@ -77,7 +77,7 @@ publish calibration profile for camera [default]</code></pre>
|
|
|
77
77
|
<tr><td><code>camera-unavailable</code></td><td>Camera Source refused the lease</td></tr>
|
|
78
78
|
<tr><td><code>camera-ended</code></td><td>The camera stopped or the device disappeared</td></tr>
|
|
79
79
|
<tr><td><code>resolution-mismatch</code></td><td>The capture resolution changed after the session started</td></tr>
|
|
80
|
-
<tr><td><code>capture-condition-mismatch</code></td><td>The camera device or mirroring changed after the session started
|
|
80
|
+
<tr><td><code>capture-condition-mismatch</code></td><td>The camera device or mirroring changed after the session started, or its resize mode, zoom or focus changed before the solve. The session ends in an error rather than solved.</td></tr>
|
|
81
81
|
<tr><td><code>board-not-found</code></td><td>The complete chessboard was not visible</td></tr>
|
|
82
82
|
<tr><td><code>sample-low-quality</code></td><td>The board was too small in frame, or too blurred</td></tr>
|
|
83
83
|
<tr><td><code>sample-too-similar</code></td><td>The view is too close to one already kept</td></tr>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-camera-calibration",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "A TurboWarp extension that calibrates a shared Camera Source camera and publishes its intrinsic calibration profile.",
|
|
5
5
|
"author": "Hiroya Kubo <hiroya@cuc.ac.jp>",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -100,6 +100,43 @@ export function captureConditionsOf(
|
|
|
100
100
|
return {capture, device};
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
/**
|
|
104
|
+
* What changed in the camera's optics since a session began, or undefined when nothing did.
|
|
105
|
+
*
|
|
106
|
+
* The members are the ones Camera Source decides a profile's fit on -- resize mode, zoom, focus
|
|
107
|
+
* mode and focus distance, compared with its tolerances, and the device label. A difference in
|
|
108
|
+
* any of them would make the profile being solved `incompatible` with this camera the moment it
|
|
109
|
+
* was registered; conditions that could be read at the start and cannot be read now would make it
|
|
110
|
+
* `undetermined`. Either way the views were not all taken under the conditions the profile is
|
|
111
|
+
* about to claim, so the session is not worth ending as solved.
|
|
112
|
+
*
|
|
113
|
+
* Frame rate, facing mode and the device id are left out for the reason Camera Source leaves them
|
|
114
|
+
* out: none of them changes how the lens projects.
|
|
115
|
+
*/
|
|
116
|
+
export function conditionsDrift(
|
|
117
|
+
recorded: {capture: CalibrationCapture; device: CalibrationDevice},
|
|
118
|
+
current: {capture: CalibrationCapture; device: CalibrationDevice} | undefined
|
|
119
|
+
): string | undefined {
|
|
120
|
+
if (!current) return 'the camera no longer reports how it is configured';
|
|
121
|
+
const changed: string[] = [];
|
|
122
|
+
const text = (name: string, left?: string, right?: string) => {
|
|
123
|
+
if (left !== right) changed.push(`${name} ${left ?? 'not reported'} -> ${right ?? 'not reported'}`);
|
|
124
|
+
};
|
|
125
|
+
const number = (name: string, left?: number, right?: number) => {
|
|
126
|
+
const same =
|
|
127
|
+
left === undefined || right === undefined ? left === right : Math.abs(left - right) <= 1e-6;
|
|
128
|
+
if (!same) changed.push(`${name} ${left ?? 'not reported'} -> ${right ?? 'not reported'}`);
|
|
129
|
+
};
|
|
130
|
+
text('resize mode', recorded.capture.resizeMode, current.capture.resizeMode);
|
|
131
|
+
number('zoom', recorded.capture.zoom, current.capture.zoom);
|
|
132
|
+
text('focus mode', recorded.capture.focusMode, current.capture.focusMode);
|
|
133
|
+
number('focus distance', recorded.capture.focusDistance, current.capture.focusDistance);
|
|
134
|
+
if (recorded.device.label !== undefined && current.device.label !== undefined) {
|
|
135
|
+
text('device', recorded.device.label, current.device.label);
|
|
136
|
+
}
|
|
137
|
+
return changed.length === 0 ? undefined : changed.join(', ');
|
|
138
|
+
}
|
|
139
|
+
|
|
103
140
|
export function requireProfileRegistry(
|
|
104
141
|
runtime: TurboWarpRuntime
|
|
105
142
|
): CameraSourceCapabilityV1 {
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
CALIBRATION_LEASE_OWNER,
|
|
3
3
|
CameraSourceError,
|
|
4
4
|
captureConditionsOf,
|
|
5
|
+
conditionsDrift,
|
|
5
6
|
requireCameraSource,
|
|
6
7
|
requireProfileRegistry,
|
|
7
8
|
toCameraSourceProfile,
|
|
@@ -473,8 +474,9 @@ class CameraCalibration {
|
|
|
473
474
|
const solving = this.automaticSolve(operation).catch(() => {
|
|
474
475
|
// A solver that cannot answer for this set is not a session-ending
|
|
475
476
|
// failure: more views may well fix it, and the operator is still
|
|
476
|
-
// collecting them.
|
|
477
|
-
|
|
477
|
+
// collecting them. A session that did end -- its camera settings changed
|
|
478
|
+
// under it -- is not told to keep going.
|
|
479
|
+
if (this.calibrationState !== 'error') this.guide('keep-going');
|
|
478
480
|
});
|
|
479
481
|
this.solving = solving;
|
|
480
482
|
const clear = () => {
|
|
@@ -1069,6 +1071,28 @@ class CameraCalibration {
|
|
|
1069
1071
|
lease: CameraLease,
|
|
1070
1072
|
solution: CalibrationSolveResult
|
|
1071
1073
|
): Promise<void> {
|
|
1074
|
+
// Solved means usable on this camera. A profile that Camera Source would
|
|
1075
|
+
// judge not to fit the camera it was just solved on is not a result to
|
|
1076
|
+
// hand over, so the session ends in an error instead: the views were taken
|
|
1077
|
+
// under conditions that no longer hold, and only a new session can fix it.
|
|
1078
|
+
// A camera that never said how it was configured has nothing to drift
|
|
1079
|
+
// from, and still calibrates.
|
|
1080
|
+
if (session.conditions) {
|
|
1081
|
+
const drift = conditionsDrift(
|
|
1082
|
+
session.conditions,
|
|
1083
|
+
captureConditionsOf(this.runtime, this.cameraId)
|
|
1084
|
+
);
|
|
1085
|
+
if (drift !== undefined) {
|
|
1086
|
+
this.stopAutomatic();
|
|
1087
|
+
await this.releaseSession();
|
|
1088
|
+
this.fail(
|
|
1089
|
+
'capture-condition-mismatch',
|
|
1090
|
+
new Error(
|
|
1091
|
+
`The camera settings changed during the calibration (${drift}). Restart the calibration for camera ${this.cameraId}.`
|
|
1092
|
+
)
|
|
1093
|
+
);
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1072
1096
|
const sampleCount = this.samples.length;
|
|
1073
1097
|
let profile: CameraIntrinsicsV1;
|
|
1074
1098
|
try {
|