@kubohiroya/turbowarp-camera-calibration 0.3.0 → 0.4.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 +9 -14
- package/README.md +9 -15
- package/dist/camera-calibration.js +10 -47
- package/docs/architecture.ja.md +12 -7
- package/docs/architecture.md +13 -8
- package/docs/index.html +0 -4
- package/package.json +2 -2
- package/src/block-definitions.json +92 -40
- package/src/extension.ts +10 -42
package/README.ja.md
CHANGED
|
@@ -73,20 +73,15 @@ flagが止めるのは実行であってバイト数ではないためです。
|
|
|
73
73
|
校正の確認は、solveに使っていない別の画像で行ってください。採用サンプルに対する
|
|
74
74
|
再投影誤差が小さいことは、その結果が一般に通用することの証明にはなりません。
|
|
75
75
|
|
|
76
|
-
##
|
|
76
|
+
## solverが読み込まれるタイミング
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
常に`idle`を返します。カメラのleaseは取得せず、OpenCVのruntimeも初期化しません。
|
|
78
|
+
機能拡張を登録した時点で全ブロックがパレットに出ており、runtime capabilityも
|
|
79
|
+
runtimeに載っています。別途有効化する操作はありません。
|
|
81
80
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
flagは一度だけ読み取って凍結します。あとから値を変えても影響しません。実行中の
|
|
89
|
-
projectが途中で契約を切り替えることを防ぐためです。
|
|
81
|
+
OpenCVのruntimeは機能拡張と一緒には読み込まれません。最初のサンプル取得か
|
|
82
|
+
solveで初めて生成されるので、`camera calibration state`や
|
|
83
|
+
`camera calibration backend`を読むだけのprojectには一切の負荷がかかりません。
|
|
84
|
+
カメラのleaseも、校正を開始するまで取得しません。
|
|
90
85
|
|
|
91
86
|
## インストール
|
|
92
87
|
|
|
@@ -106,7 +101,7 @@ bundleは約11 MBあります。
|
|
|
106
101
|
検証済みのversionをexact pinします。
|
|
107
102
|
|
|
108
103
|
```bash
|
|
109
|
-
pnpm add --save-exact @kubohiroya/turbowarp-camera-calibration@0.
|
|
104
|
+
pnpm add --save-exact @kubohiroya/turbowarp-camera-calibration@0.4.0
|
|
110
105
|
```
|
|
111
106
|
|
|
112
107
|
standalone bundle:
|
|
@@ -118,7 +113,7 @@ node_modules/@kubohiroya/turbowarp-camera-calibration/dist/camera-calibration.js
|
|
|
118
113
|
version固定CDN URL:
|
|
119
114
|
|
|
120
115
|
```text
|
|
121
|
-
https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-calibration@0.
|
|
116
|
+
https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-calibration@0.4.0/dist/camera-calibration.js
|
|
122
117
|
```
|
|
123
118
|
|
|
124
119
|
## クイックスタート
|
package/README.md
CHANGED
|
@@ -74,21 +74,15 @@ Verify a finished calibration against images that were not part of the solve. A
|
|
|
74
74
|
low reprojection error on the calibration samples alone does not prove the
|
|
75
75
|
result generalizes.
|
|
76
76
|
|
|
77
|
-
##
|
|
77
|
+
## When the solver loads
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
`camera calibration state` reporter is published and it answers `idle`; no
|
|
82
|
-
camera lease is taken and the OpenCV runtime is never initialized.
|
|
79
|
+
Every block is in the palette as soon as the extension is registered, and the
|
|
80
|
+
runtime capability is on the runtime. Nothing is switched on separately.
|
|
83
81
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
The flags are read once and frozen. Changing the value afterwards has no effect,
|
|
91
|
-
which keeps a running project from switching contracts mid-session.
|
|
82
|
+
The OpenCV runtime is not loaded with the extension. It is created on the first
|
|
83
|
+
sample or solve and never before, so a project that only reads
|
|
84
|
+
`camera calibration state` or `camera calibration backend` pays nothing for it.
|
|
85
|
+
No camera lease is taken until a calibration starts.
|
|
92
86
|
|
|
93
87
|
## Installation
|
|
94
88
|
|
|
@@ -108,7 +102,7 @@ therefore about 11 MB.
|
|
|
108
102
|
Install an exact version that you have reviewed:
|
|
109
103
|
|
|
110
104
|
```bash
|
|
111
|
-
pnpm add --save-exact @kubohiroya/turbowarp-camera-calibration@0.
|
|
105
|
+
pnpm add --save-exact @kubohiroya/turbowarp-camera-calibration@0.4.0
|
|
112
106
|
```
|
|
113
107
|
|
|
114
108
|
Load the standalone bundle from:
|
|
@@ -120,7 +114,7 @@ node_modules/@kubohiroya/turbowarp-camera-calibration/dist/camera-calibration.js
|
|
|
120
114
|
A version-pinned CDN URL is:
|
|
121
115
|
|
|
122
116
|
```text
|
|
123
|
-
https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-calibration@0.
|
|
117
|
+
https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-calibration@0.4.0/dist/camera-calibration.js
|
|
124
118
|
```
|
|
125
119
|
|
|
126
120
|
## Quick start
|
|
@@ -42,16 +42,11 @@
|
|
|
42
42
|
docsURI: "https://kubohiroya.github.io/turbowarp-camera-calibration/",
|
|
43
43
|
blockIconURI: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0OCA0OCI+PHJlY3QgeD0iNCIgeT0iNCIgd2lkdGg9IjQwIiBoZWlnaHQ9IjQwIiByeD0iNCIgZmlsbD0iI2ZmZmZmZiIgc3Ryb2tlPSIjNEM5N0ZGIiBzdHJva2Utd2lkdGg9IjIiLz48ZyBmaWxsPSIjNEM5N0ZGIj48cmVjdCB4PSI2IiB5PSI2IiB3aWR0aD0iOSIgaGVpZ2h0PSI5Ii8+PHJlY3QgeD0iMjQiIHk9IjYiIHdpZHRoPSI5IiBoZWlnaHQ9IjkiLz48cmVjdCB4PSIxNSIgeT0iMTUiIHdpZHRoPSI5IiBoZWlnaHQ9IjkiLz48cmVjdCB4PSIzMyIgeT0iMTUiIHdpZHRoPSI5IiBoZWlnaHQ9IjkiLz48cmVjdCB4PSI2IiB5PSIyNCIgd2lkdGg9IjkiIGhlaWdodD0iOSIvPjxyZWN0IHg9IjI0IiB5PSIyNCIgd2lkdGg9IjkiIGhlaWdodD0iOSIvPjxyZWN0IHg9IjE1IiB5PSIzMyIgd2lkdGg9IjkiIGhlaWdodD0iOSIvPjxyZWN0IHg9IjMzIiB5PSIzMyIgd2lkdGg9IjkiIGhlaWdodD0iOSIvPjwvZz48L3N2Zz4="
|
|
44
44
|
};
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region config/feature-flags.ts
|
|
47
|
-
var overrides = globalThis.__TWCC_FEATURE_FLAGS__;
|
|
48
|
-
var featureFlags = Object.freeze({ cameraCalibrationV1: overrides?.cameraCalibrationV1 === true });
|
|
49
45
|
var block_definitions_default = {
|
|
50
46
|
extensionName: "TurboWarp-Camera-Calibration",
|
|
51
47
|
blocks: [
|
|
52
48
|
{
|
|
53
49
|
"opcode": "startCameraCalibration",
|
|
54
|
-
"feature": "cameraCalibrationV1",
|
|
55
50
|
"blockType": "COMMAND",
|
|
56
51
|
"text": "start camera [CAMERA_ID] calibration [CALIBRATION_ID] board [COLUMNS] by [ROWS] square [SQUARE_METERS] m max error [MAX_ERROR_PX] px",
|
|
57
52
|
"description": "Leases one shared Camera Source camera and fixes its real capture resolution for a chessboard calibration session. The board is measured in inner corners, not printed squares.",
|
|
@@ -84,7 +79,6 @@
|
|
|
84
79
|
},
|
|
85
80
|
{
|
|
86
81
|
"opcode": "addCameraCalibrationSample",
|
|
87
|
-
"feature": "cameraCalibrationV1",
|
|
88
82
|
"blockType": "COMMAND",
|
|
89
83
|
"text": "add calibration sample for camera [CAMERA_ID]",
|
|
90
84
|
"description": "Detects the complete board in the current shared frame and retains it when its quality and its novelty against the retained samples both pass.",
|
|
@@ -95,7 +89,6 @@
|
|
|
95
89
|
},
|
|
96
90
|
{
|
|
97
91
|
"opcode": "solveCameraCalibration",
|
|
98
|
-
"feature": "cameraCalibrationV1",
|
|
99
92
|
"blockType": "COMMAND",
|
|
100
93
|
"text": "solve calibration for camera [CAMERA_ID]",
|
|
101
94
|
"description": "Solves the intrinsic matrix and distortion coefficients from at least eight accepted samples, then releases the camera lease. No external pose is produced.",
|
|
@@ -106,7 +99,6 @@
|
|
|
106
99
|
},
|
|
107
100
|
{
|
|
108
101
|
"opcode": "cancelCameraCalibration",
|
|
109
|
-
"feature": "cameraCalibrationV1",
|
|
110
102
|
"blockType": "COMMAND",
|
|
111
103
|
"text": "cancel calibration for camera [CAMERA_ID]",
|
|
112
104
|
"description": "Releases the camera lease and the retained samples while preserving the last validated profile.",
|
|
@@ -117,7 +109,6 @@
|
|
|
117
109
|
},
|
|
118
110
|
{
|
|
119
111
|
"opcode": "cleanupCameraCalibration",
|
|
120
|
-
"feature": "cameraCalibrationV1",
|
|
121
112
|
"blockType": "COMMAND",
|
|
122
113
|
"text": "cleanup calibration for camera [CAMERA_ID]",
|
|
123
114
|
"description": "Releases the session and also clears the in-memory calibration profile for that camera.",
|
|
@@ -128,7 +119,6 @@
|
|
|
128
119
|
},
|
|
129
120
|
{
|
|
130
121
|
"opcode": "publishCameraCalibration",
|
|
131
|
-
"feature": "cameraCalibrationV1",
|
|
132
122
|
"blockType": "COMMAND",
|
|
133
123
|
"text": "publish calibration profile for camera [CAMERA_ID]",
|
|
134
124
|
"description": "Registers the solved profile with Camera Source, which owns the profile contract. Reports an explicit error when Camera Source is absent, speaks another contract version, or has no profile to publish.",
|
|
@@ -139,7 +129,6 @@
|
|
|
139
129
|
},
|
|
140
130
|
{
|
|
141
131
|
"opcode": "importCameraCalibration",
|
|
142
|
-
"feature": "cameraCalibrationV1",
|
|
143
132
|
"blockType": "COMMAND",
|
|
144
133
|
"text": "import calibration profile [JSON] for camera [CAMERA_ID]",
|
|
145
134
|
"description": "Imports a calibration profile after schema, credential, and applicability checks. Pre-migration profiles are accepted and their world pose is dropped rather than reinterpreted.",
|
|
@@ -156,7 +145,6 @@
|
|
|
156
145
|
},
|
|
157
146
|
{
|
|
158
147
|
"opcode": "cameraCalibrationJsonValid",
|
|
159
|
-
"feature": "cameraCalibrationV1",
|
|
160
148
|
"blockType": "BOOLEAN",
|
|
161
149
|
"text": "calibration profile [JSON] valid for camera [CAMERA_ID]?",
|
|
162
150
|
"description": "Validates a profile and records why it failed, without replacing the stored profile.",
|
|
@@ -173,7 +161,6 @@
|
|
|
173
161
|
},
|
|
174
162
|
{
|
|
175
163
|
"opcode": "cameraCalibrationReady",
|
|
176
|
-
"feature": "cameraCalibrationV1",
|
|
177
164
|
"blockType": "BOOLEAN",
|
|
178
165
|
"text": "camera [CAMERA_ID] calibration ready?",
|
|
179
166
|
"description": "Reports whether a fixed-resolution session for that camera can accept a sample or solve.",
|
|
@@ -184,7 +171,6 @@
|
|
|
184
171
|
},
|
|
185
172
|
{
|
|
186
173
|
"opcode": "cameraCalibrationState",
|
|
187
|
-
"feature": "always",
|
|
188
174
|
"blockType": "REPORTER",
|
|
189
175
|
"text": "camera calibration state [CAMERA_ID]",
|
|
190
176
|
"description": "Returns the calibration session state for one shared Camera Source camera: idle, acquiring-camera, sampling, ready, solving, solved, cancelling, or error. A camera that has never been calibrated reports idle.",
|
|
@@ -195,7 +181,6 @@
|
|
|
195
181
|
},
|
|
196
182
|
{
|
|
197
183
|
"opcode": "cameraCalibrationBackend",
|
|
198
|
-
"feature": "cameraCalibrationV1",
|
|
199
184
|
"blockType": "REPORTER",
|
|
200
185
|
"text": "camera calibration backend",
|
|
201
186
|
"description": "Returns the pinned solver identifier. Reading it does not load the solver.",
|
|
@@ -203,7 +188,6 @@
|
|
|
203
188
|
},
|
|
204
189
|
{
|
|
205
190
|
"opcode": "cameraCalibrationSampleCount",
|
|
206
|
-
"feature": "cameraCalibrationV1",
|
|
207
191
|
"blockType": "REPORTER",
|
|
208
192
|
"text": "camera [CAMERA_ID] calibration sample count",
|
|
209
193
|
"description": "Returns the accepted sample count for the current or last solved session.",
|
|
@@ -214,7 +198,6 @@
|
|
|
214
198
|
},
|
|
215
199
|
{
|
|
216
200
|
"opcode": "cameraCalibrationSampleQuality",
|
|
217
|
-
"feature": "cameraCalibrationV1",
|
|
218
201
|
"blockType": "REPORTER",
|
|
219
202
|
"text": "camera [CAMERA_ID] calibration sample quality",
|
|
220
203
|
"description": "Returns the latest accepted sample's combined board coverage and sharpness score, from zero to one.",
|
|
@@ -225,7 +208,6 @@
|
|
|
225
208
|
},
|
|
226
209
|
{
|
|
227
210
|
"opcode": "cameraCalibrationReprojectionError",
|
|
228
|
-
"feature": "cameraCalibrationV1",
|
|
229
211
|
"blockType": "REPORTER",
|
|
230
212
|
"text": "camera [CAMERA_ID] calibration reprojection error px",
|
|
231
213
|
"description": "Returns the RMS reprojection error in pixels for the latest solve or imported profile.",
|
|
@@ -236,7 +218,6 @@
|
|
|
236
218
|
},
|
|
237
219
|
{
|
|
238
220
|
"opcode": "cameraCalibrationErrorCode",
|
|
239
|
-
"feature": "cameraCalibrationV1",
|
|
240
221
|
"blockType": "REPORTER",
|
|
241
222
|
"text": "camera [CAMERA_ID] calibration error code",
|
|
242
223
|
"description": "Returns a stable code for dependency, board, camera, sample, solve, reprojection, profile, or publication errors, or an empty string.",
|
|
@@ -247,7 +228,6 @@
|
|
|
247
228
|
},
|
|
248
229
|
{
|
|
249
230
|
"opcode": "cameraCalibrationError",
|
|
250
|
-
"feature": "cameraCalibrationV1",
|
|
251
231
|
"blockType": "REPORTER",
|
|
252
232
|
"text": "camera [CAMERA_ID] calibration error",
|
|
253
233
|
"description": "Returns the detailed calibration diagnostic for that camera.",
|
|
@@ -258,7 +238,6 @@
|
|
|
258
238
|
},
|
|
259
239
|
{
|
|
260
240
|
"opcode": "cameraCalibrationJson",
|
|
261
|
-
"feature": "cameraCalibrationV1",
|
|
262
241
|
"blockType": "REPORTER",
|
|
263
242
|
"text": "camera [CAMERA_ID] calibration profile JSON",
|
|
264
243
|
"description": "Exports the stored intrinsic profile for that camera, or an empty string when none exists.",
|
|
@@ -8700,8 +8679,6 @@
|
|
|
8700
8679
|
//#region src/extension.ts
|
|
8701
8680
|
var blockDefinitions = block_definitions_default.blocks;
|
|
8702
8681
|
var defaultCameraId = "default";
|
|
8703
|
-
/** The state reported for a camera that has no calibration session. */
|
|
8704
|
-
var IDLE_CALIBRATION_STATE = "idle";
|
|
8705
8682
|
function normalizeId(value, fallback = defaultCameraId) {
|
|
8706
8683
|
return String(value ?? "").trim() || fallback;
|
|
8707
8684
|
}
|
|
@@ -8718,14 +8695,13 @@
|
|
|
8718
8695
|
this.controller.cleanupAll();
|
|
8719
8696
|
};
|
|
8720
8697
|
this.runtime = options.runtime ?? Scratch.vm.runtime;
|
|
8721
|
-
this.enabled = options.enabled ?? featureFlags.cameraCalibrationV1;
|
|
8722
8698
|
const nowMilliseconds = options.nowMilliseconds;
|
|
8723
8699
|
this.controller = new CameraCalibrationController({
|
|
8724
8700
|
runtime: this.runtime,
|
|
8725
8701
|
backend: options.backend ?? openCvBackendFactory,
|
|
8726
8702
|
...nowMilliseconds ? { nowMilliseconds } : {}
|
|
8727
8703
|
});
|
|
8728
|
-
|
|
8704
|
+
this.runtime[runtimeCapabilityKey] = this.createCapability();
|
|
8729
8705
|
this.runtime.on?.("PROJECT_STOP_ALL", this.handleProjectBoundary);
|
|
8730
8706
|
this.runtime.on?.("PROJECT_LOADED", this.handleProjectBoundary);
|
|
8731
8707
|
this.runtime.on?.("RUNTIME_DISPOSED", this.handleDisposed);
|
|
@@ -8736,11 +8712,10 @@
|
|
|
8736
8712
|
name: Scratch.translate(block_definitions_default.extensionName),
|
|
8737
8713
|
docsURI: extensionConfig.docsURI,
|
|
8738
8714
|
blockIconURI: extensionConfig.blockIconURI,
|
|
8739
|
-
blocks: blockDefinitions.
|
|
8715
|
+
blocks: blockDefinitions.map((block) => this.toScratchBlock(block))
|
|
8740
8716
|
};
|
|
8741
8717
|
}
|
|
8742
8718
|
async startCameraCalibration(args) {
|
|
8743
|
-
this.requireEnabled();
|
|
8744
8719
|
await this.controller.start({
|
|
8745
8720
|
cameraId: normalizeId(args.CAMERA_ID),
|
|
8746
8721
|
calibrationId: Scratch.Cast.toString(args.CALIBRATION_ID).trim(),
|
|
@@ -8753,11 +8728,9 @@
|
|
|
8753
8728
|
});
|
|
8754
8729
|
}
|
|
8755
8730
|
async addCameraCalibrationSample(args) {
|
|
8756
|
-
this.requireEnabled();
|
|
8757
8731
|
await this.controller.addSample(normalizeId(args.CAMERA_ID));
|
|
8758
8732
|
}
|
|
8759
8733
|
async solveCameraCalibration(args) {
|
|
8760
|
-
this.requireEnabled();
|
|
8761
8734
|
await this.controller.solve(normalizeId(args.CAMERA_ID));
|
|
8762
8735
|
}
|
|
8763
8736
|
async cancelCameraCalibration(args) {
|
|
@@ -8767,44 +8740,40 @@
|
|
|
8767
8740
|
await this.controller.cleanup(normalizeId(args.CAMERA_ID));
|
|
8768
8741
|
}
|
|
8769
8742
|
async publishCameraCalibration(args) {
|
|
8770
|
-
this.requireEnabled();
|
|
8771
8743
|
await this.controller.publishProfile(normalizeId(args.CAMERA_ID));
|
|
8772
8744
|
}
|
|
8773
8745
|
async importCameraCalibration(args) {
|
|
8774
|
-
this.requireEnabled();
|
|
8775
8746
|
await this.controller.importProfile(normalizeId(args.CAMERA_ID), Scratch.Cast.toString(args.JSON));
|
|
8776
8747
|
}
|
|
8777
8748
|
cameraCalibrationJsonValid(args) {
|
|
8778
|
-
if (!this.enabled) return false;
|
|
8779
8749
|
return this.controller.validateProfile(normalizeId(args.CAMERA_ID), Scratch.Cast.toString(args.JSON));
|
|
8780
8750
|
}
|
|
8781
8751
|
cameraCalibrationReady(args) {
|
|
8782
|
-
return this.
|
|
8752
|
+
return this.controller.ready(normalizeId(args.CAMERA_ID));
|
|
8783
8753
|
}
|
|
8784
8754
|
cameraCalibrationState(args = {}) {
|
|
8785
|
-
if (!this.enabled) return IDLE_CALIBRATION_STATE;
|
|
8786
8755
|
return this.controller.state(normalizeId(args.CAMERA_ID));
|
|
8787
8756
|
}
|
|
8788
8757
|
cameraCalibrationBackend() {
|
|
8789
|
-
return this.
|
|
8758
|
+
return this.controller.backend();
|
|
8790
8759
|
}
|
|
8791
8760
|
cameraCalibrationSampleCount(args) {
|
|
8792
|
-
return this.
|
|
8761
|
+
return this.controller.sampleCount(normalizeId(args.CAMERA_ID));
|
|
8793
8762
|
}
|
|
8794
8763
|
cameraCalibrationSampleQuality(args) {
|
|
8795
|
-
return this.
|
|
8764
|
+
return this.controller.latestSampleQuality(normalizeId(args.CAMERA_ID));
|
|
8796
8765
|
}
|
|
8797
8766
|
cameraCalibrationReprojectionError(args) {
|
|
8798
|
-
return this.
|
|
8767
|
+
return this.controller.latestReprojectionError(normalizeId(args.CAMERA_ID));
|
|
8799
8768
|
}
|
|
8800
8769
|
cameraCalibrationErrorCode(args) {
|
|
8801
|
-
return this.
|
|
8770
|
+
return this.controller.errorCode(normalizeId(args.CAMERA_ID));
|
|
8802
8771
|
}
|
|
8803
8772
|
cameraCalibrationError(args) {
|
|
8804
|
-
return this.
|
|
8773
|
+
return this.controller.errorMessage(normalizeId(args.CAMERA_ID));
|
|
8805
8774
|
}
|
|
8806
8775
|
cameraCalibrationJson(args) {
|
|
8807
|
-
return this.
|
|
8776
|
+
return this.controller.profileJson(normalizeId(args.CAMERA_ID));
|
|
8808
8777
|
}
|
|
8809
8778
|
/**
|
|
8810
8779
|
* The procedure, named rather than reached through opcodes.
|
|
@@ -8838,12 +8807,6 @@
|
|
|
8838
8807
|
});
|
|
8839
8808
|
return this.capability;
|
|
8840
8809
|
}
|
|
8841
|
-
blockEnabled(feature) {
|
|
8842
|
-
return feature === "always" || this.enabled;
|
|
8843
|
-
}
|
|
8844
|
-
requireEnabled() {
|
|
8845
|
-
if (!this.enabled) throw new Error("Camera calibration v1 is disabled. Enable it before the project starts.");
|
|
8846
|
-
}
|
|
8847
8810
|
toScratchBlock(block) {
|
|
8848
8811
|
return {
|
|
8849
8812
|
opcode: block.opcode,
|
package/docs/architecture.ja.md
CHANGED
|
@@ -62,7 +62,6 @@ block、argument、menuはserialize前に識別子で整列します。text、de
|
|
|
62
62
|
## moduleの構成
|
|
63
63
|
|
|
64
64
|
```text
|
|
65
|
-
config/feature-flags.ts 起動時固定のflag。校正は既定OFF
|
|
66
65
|
src/calibration/types.ts board、sample、solve結果、backendの継ぎ目
|
|
67
66
|
src/calibration/profile.ts 内部校正プロファイル、その検証、旧形式のadapter
|
|
68
67
|
src/calibration/camera-source.ts Camera Source capabilityのclient
|
|
@@ -138,13 +137,19 @@ Camera Sourceのcapabilityは必要になった時点でruntimeから参照し
|
|
|
138
137
|
solve済みのままであり、すでに失敗したセッションがpublish要求で回復することも
|
|
139
138
|
ありません。
|
|
140
139
|
|
|
141
|
-
##
|
|
140
|
+
## この機能拡張を読み込む費用
|
|
142
141
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
142
|
+
全ブロックとruntime capabilityは、機能拡張の登録時点で公開されます。
|
|
143
|
+
切り替えスイッチはありません。
|
|
144
|
+
|
|
145
|
+
登録自体は安価です。OpenCVのruntimeは最初のサンプル取得かsolveで初めて生成
|
|
146
|
+
されるので、状態やbackend名を読むだけのprojectでは初期化されません。カメラの
|
|
147
|
+
leaseも校正を開始するまで要求しません。これらはflagが守っているのではなく、
|
|
148
|
+
コードがどこで生成しているかによって成り立っています。
|
|
149
|
+
|
|
150
|
+
ロールバックは「この機能拡張を読み込まない」ことです。自前の校正経路を残して
|
|
151
|
+
いる利用側は、projectから外すだけで旧経路へ戻せます。これは委譲するかどうかと
|
|
152
|
+
いう、すでに下している判断と同じものです。
|
|
148
153
|
|
|
149
154
|
## drift検出
|
|
150
155
|
|
package/docs/architecture.md
CHANGED
|
@@ -65,7 +65,6 @@ references.
|
|
|
65
65
|
## Module layout
|
|
66
66
|
|
|
67
67
|
```text
|
|
68
|
-
config/feature-flags.ts startup-fixed flags, calibration OFF by default
|
|
69
68
|
src/calibration/types.ts board, sample, solve result, backend seam
|
|
70
69
|
src/calibration/profile.ts the intrinsic profile, its validator, legacy adapter
|
|
71
70
|
src/calibration/camera-source.ts the Camera Source capability client
|
|
@@ -143,14 +142,20 @@ state. Publishing is not a session operation: a solved profile that Camera
|
|
|
143
142
|
Source could not accept is still solved, and a session that already failed is
|
|
144
143
|
not repaired by asking to publish.
|
|
145
144
|
|
|
146
|
-
##
|
|
145
|
+
## What loading this extension costs
|
|
147
146
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
147
|
+
Every block and the runtime capability are published as soon as the extension
|
|
148
|
+
registers. There is no switch.
|
|
149
|
+
|
|
150
|
+
Registering is cheap. The OpenCV runtime is created on the first sample or
|
|
151
|
+
solve and never before, so a project that only reads the state or the backend
|
|
152
|
+
name never initializes it, and no camera lease is requested until a calibration
|
|
153
|
+
starts. Those hold because of where the code creates things, not because of a
|
|
154
|
+
flag guarding them.
|
|
155
|
+
|
|
156
|
+
Rolling back means not loading this extension. A consumer that still has its
|
|
157
|
+
own calibration path falls back by leaving this one out of the project, which
|
|
158
|
+
is the same decision it was already making about whether to delegate.
|
|
154
159
|
|
|
155
160
|
## Drift detection
|
|
156
161
|
|
package/docs/index.html
CHANGED
|
@@ -26,10 +26,6 @@
|
|
|
26
26
|
<li>The extension must run without the sandbox.</li>
|
|
27
27
|
</ul>
|
|
28
28
|
|
|
29
|
-
<h2>Enabling calibration</h2>
|
|
30
|
-
<p>Set the override before the extension is registered. The flags are read once and frozen.</p>
|
|
31
|
-
<pre><code>globalThis.__TWCC_FEATURE_FLAGS__ = {cameraCalibrationV1: true};</code></pre>
|
|
32
|
-
|
|
33
29
|
<h2>Calibrating a camera</h2>
|
|
34
30
|
<pre><code>start shared camera [default]
|
|
35
31
|
start camera [default] calibration [calibration-1] board [9] by [6] square [0.025] m max error [1.5] px
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-camera-calibration",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"dev": "vite build --watch",
|
|
59
59
|
"typecheck": "tsc --noEmit",
|
|
60
60
|
"build": "vite build && tsc -p tsconfig.lib.json",
|
|
61
|
-
"lint": "eslint
|
|
61
|
+
"lint": "eslint src tests scripts vite.config.ts",
|
|
62
62
|
"test": "vitest run",
|
|
63
63
|
"docs": "node scripts/generate-readme.ts",
|
|
64
64
|
"docs:check": "pnpm run docs && git diff --exit-code -- README.md",
|
|
@@ -3,114 +3,154 @@
|
|
|
3
3
|
"blocks": [
|
|
4
4
|
{
|
|
5
5
|
"opcode": "startCameraCalibration",
|
|
6
|
-
"feature": "cameraCalibrationV1",
|
|
7
6
|
"blockType": "COMMAND",
|
|
8
7
|
"text": "start camera [CAMERA_ID] calibration [CALIBRATION_ID] board [COLUMNS] by [ROWS] square [SQUARE_METERS] m max error [MAX_ERROR_PX] px",
|
|
9
8
|
"description": "Leases one shared Camera Source camera and fixes its real capture resolution for a chessboard calibration session. The board is measured in inner corners, not printed squares.",
|
|
10
9
|
"arguments": {
|
|
11
|
-
"CAMERA_ID": {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
10
|
+
"CAMERA_ID": {
|
|
11
|
+
"type": "STRING",
|
|
12
|
+
"defaultValue": "default"
|
|
13
|
+
},
|
|
14
|
+
"CALIBRATION_ID": {
|
|
15
|
+
"type": "STRING",
|
|
16
|
+
"defaultValue": "calibration-1"
|
|
17
|
+
},
|
|
18
|
+
"COLUMNS": {
|
|
19
|
+
"type": "NUMBER",
|
|
20
|
+
"defaultValue": 9
|
|
21
|
+
},
|
|
22
|
+
"ROWS": {
|
|
23
|
+
"type": "NUMBER",
|
|
24
|
+
"defaultValue": 6
|
|
25
|
+
},
|
|
26
|
+
"SQUARE_METERS": {
|
|
27
|
+
"type": "NUMBER",
|
|
28
|
+
"defaultValue": 0.025
|
|
29
|
+
},
|
|
30
|
+
"MAX_ERROR_PX": {
|
|
31
|
+
"type": "NUMBER",
|
|
32
|
+
"defaultValue": 1.5
|
|
33
|
+
}
|
|
17
34
|
}
|
|
18
35
|
},
|
|
19
36
|
{
|
|
20
37
|
"opcode": "addCameraCalibrationSample",
|
|
21
|
-
"feature": "cameraCalibrationV1",
|
|
22
38
|
"blockType": "COMMAND",
|
|
23
39
|
"text": "add calibration sample for camera [CAMERA_ID]",
|
|
24
40
|
"description": "Detects the complete board in the current shared frame and retains it when its quality and its novelty against the retained samples both pass.",
|
|
25
41
|
"arguments": {
|
|
26
|
-
"CAMERA_ID": {
|
|
42
|
+
"CAMERA_ID": {
|
|
43
|
+
"type": "STRING",
|
|
44
|
+
"defaultValue": "default"
|
|
45
|
+
}
|
|
27
46
|
}
|
|
28
47
|
},
|
|
29
48
|
{
|
|
30
49
|
"opcode": "solveCameraCalibration",
|
|
31
|
-
"feature": "cameraCalibrationV1",
|
|
32
50
|
"blockType": "COMMAND",
|
|
33
51
|
"text": "solve calibration for camera [CAMERA_ID]",
|
|
34
52
|
"description": "Solves the intrinsic matrix and distortion coefficients from at least eight accepted samples, then releases the camera lease. No external pose is produced.",
|
|
35
53
|
"arguments": {
|
|
36
|
-
"CAMERA_ID": {
|
|
54
|
+
"CAMERA_ID": {
|
|
55
|
+
"type": "STRING",
|
|
56
|
+
"defaultValue": "default"
|
|
57
|
+
}
|
|
37
58
|
}
|
|
38
59
|
},
|
|
39
60
|
{
|
|
40
61
|
"opcode": "cancelCameraCalibration",
|
|
41
|
-
"feature": "cameraCalibrationV1",
|
|
42
62
|
"blockType": "COMMAND",
|
|
43
63
|
"text": "cancel calibration for camera [CAMERA_ID]",
|
|
44
64
|
"description": "Releases the camera lease and the retained samples while preserving the last validated profile.",
|
|
45
65
|
"arguments": {
|
|
46
|
-
"CAMERA_ID": {
|
|
66
|
+
"CAMERA_ID": {
|
|
67
|
+
"type": "STRING",
|
|
68
|
+
"defaultValue": "default"
|
|
69
|
+
}
|
|
47
70
|
}
|
|
48
71
|
},
|
|
49
72
|
{
|
|
50
73
|
"opcode": "cleanupCameraCalibration",
|
|
51
|
-
"feature": "cameraCalibrationV1",
|
|
52
74
|
"blockType": "COMMAND",
|
|
53
75
|
"text": "cleanup calibration for camera [CAMERA_ID]",
|
|
54
76
|
"description": "Releases the session and also clears the in-memory calibration profile for that camera.",
|
|
55
77
|
"arguments": {
|
|
56
|
-
"CAMERA_ID": {
|
|
78
|
+
"CAMERA_ID": {
|
|
79
|
+
"type": "STRING",
|
|
80
|
+
"defaultValue": "default"
|
|
81
|
+
}
|
|
57
82
|
}
|
|
58
83
|
},
|
|
59
84
|
{
|
|
60
85
|
"opcode": "publishCameraCalibration",
|
|
61
|
-
"feature": "cameraCalibrationV1",
|
|
62
86
|
"blockType": "COMMAND",
|
|
63
87
|
"text": "publish calibration profile for camera [CAMERA_ID]",
|
|
64
88
|
"description": "Registers the solved profile with Camera Source, which owns the profile contract. Reports an explicit error when Camera Source is absent, speaks another contract version, or has no profile to publish.",
|
|
65
89
|
"arguments": {
|
|
66
|
-
"CAMERA_ID": {
|
|
90
|
+
"CAMERA_ID": {
|
|
91
|
+
"type": "STRING",
|
|
92
|
+
"defaultValue": "default"
|
|
93
|
+
}
|
|
67
94
|
}
|
|
68
95
|
},
|
|
69
96
|
{
|
|
70
97
|
"opcode": "importCameraCalibration",
|
|
71
|
-
"feature": "cameraCalibrationV1",
|
|
72
98
|
"blockType": "COMMAND",
|
|
73
99
|
"text": "import calibration profile [JSON] for camera [CAMERA_ID]",
|
|
74
100
|
"description": "Imports a calibration profile after schema, credential, and applicability checks. Pre-migration profiles are accepted and their world pose is dropped rather than reinterpreted.",
|
|
75
101
|
"arguments": {
|
|
76
|
-
"JSON": {
|
|
77
|
-
|
|
102
|
+
"JSON": {
|
|
103
|
+
"type": "STRING",
|
|
104
|
+
"defaultValue": "{}"
|
|
105
|
+
},
|
|
106
|
+
"CAMERA_ID": {
|
|
107
|
+
"type": "STRING",
|
|
108
|
+
"defaultValue": "default"
|
|
109
|
+
}
|
|
78
110
|
}
|
|
79
111
|
},
|
|
80
112
|
{
|
|
81
113
|
"opcode": "cameraCalibrationJsonValid",
|
|
82
|
-
"feature": "cameraCalibrationV1",
|
|
83
114
|
"blockType": "BOOLEAN",
|
|
84
115
|
"text": "calibration profile [JSON] valid for camera [CAMERA_ID]?",
|
|
85
116
|
"description": "Validates a profile and records why it failed, without replacing the stored profile.",
|
|
86
117
|
"arguments": {
|
|
87
|
-
"JSON": {
|
|
88
|
-
|
|
118
|
+
"JSON": {
|
|
119
|
+
"type": "STRING",
|
|
120
|
+
"defaultValue": "{}"
|
|
121
|
+
},
|
|
122
|
+
"CAMERA_ID": {
|
|
123
|
+
"type": "STRING",
|
|
124
|
+
"defaultValue": "default"
|
|
125
|
+
}
|
|
89
126
|
}
|
|
90
127
|
},
|
|
91
128
|
{
|
|
92
129
|
"opcode": "cameraCalibrationReady",
|
|
93
|
-
"feature": "cameraCalibrationV1",
|
|
94
130
|
"blockType": "BOOLEAN",
|
|
95
131
|
"text": "camera [CAMERA_ID] calibration ready?",
|
|
96
132
|
"description": "Reports whether a fixed-resolution session for that camera can accept a sample or solve.",
|
|
97
133
|
"arguments": {
|
|
98
|
-
"CAMERA_ID": {
|
|
134
|
+
"CAMERA_ID": {
|
|
135
|
+
"type": "STRING",
|
|
136
|
+
"defaultValue": "default"
|
|
137
|
+
}
|
|
99
138
|
}
|
|
100
139
|
},
|
|
101
140
|
{
|
|
102
141
|
"opcode": "cameraCalibrationState",
|
|
103
|
-
"feature": "always",
|
|
104
142
|
"blockType": "REPORTER",
|
|
105
143
|
"text": "camera calibration state [CAMERA_ID]",
|
|
106
144
|
"description": "Returns the calibration session state for one shared Camera Source camera: idle, acquiring-camera, sampling, ready, solving, solved, cancelling, or error. A camera that has never been calibrated reports idle.",
|
|
107
145
|
"arguments": {
|
|
108
|
-
"CAMERA_ID": {
|
|
146
|
+
"CAMERA_ID": {
|
|
147
|
+
"type": "STRING",
|
|
148
|
+
"defaultValue": "default"
|
|
149
|
+
}
|
|
109
150
|
}
|
|
110
151
|
},
|
|
111
152
|
{
|
|
112
153
|
"opcode": "cameraCalibrationBackend",
|
|
113
|
-
"feature": "cameraCalibrationV1",
|
|
114
154
|
"blockType": "REPORTER",
|
|
115
155
|
"text": "camera calibration backend",
|
|
116
156
|
"description": "Returns the pinned solver identifier. Reading it does not load the solver.",
|
|
@@ -118,62 +158,74 @@
|
|
|
118
158
|
},
|
|
119
159
|
{
|
|
120
160
|
"opcode": "cameraCalibrationSampleCount",
|
|
121
|
-
"feature": "cameraCalibrationV1",
|
|
122
161
|
"blockType": "REPORTER",
|
|
123
162
|
"text": "camera [CAMERA_ID] calibration sample count",
|
|
124
163
|
"description": "Returns the accepted sample count for the current or last solved session.",
|
|
125
164
|
"arguments": {
|
|
126
|
-
"CAMERA_ID": {
|
|
165
|
+
"CAMERA_ID": {
|
|
166
|
+
"type": "STRING",
|
|
167
|
+
"defaultValue": "default"
|
|
168
|
+
}
|
|
127
169
|
}
|
|
128
170
|
},
|
|
129
171
|
{
|
|
130
172
|
"opcode": "cameraCalibrationSampleQuality",
|
|
131
|
-
"feature": "cameraCalibrationV1",
|
|
132
173
|
"blockType": "REPORTER",
|
|
133
174
|
"text": "camera [CAMERA_ID] calibration sample quality",
|
|
134
175
|
"description": "Returns the latest accepted sample's combined board coverage and sharpness score, from zero to one.",
|
|
135
176
|
"arguments": {
|
|
136
|
-
"CAMERA_ID": {
|
|
177
|
+
"CAMERA_ID": {
|
|
178
|
+
"type": "STRING",
|
|
179
|
+
"defaultValue": "default"
|
|
180
|
+
}
|
|
137
181
|
}
|
|
138
182
|
},
|
|
139
183
|
{
|
|
140
184
|
"opcode": "cameraCalibrationReprojectionError",
|
|
141
|
-
"feature": "cameraCalibrationV1",
|
|
142
185
|
"blockType": "REPORTER",
|
|
143
186
|
"text": "camera [CAMERA_ID] calibration reprojection error px",
|
|
144
187
|
"description": "Returns the RMS reprojection error in pixels for the latest solve or imported profile.",
|
|
145
188
|
"arguments": {
|
|
146
|
-
"CAMERA_ID": {
|
|
189
|
+
"CAMERA_ID": {
|
|
190
|
+
"type": "STRING",
|
|
191
|
+
"defaultValue": "default"
|
|
192
|
+
}
|
|
147
193
|
}
|
|
148
194
|
},
|
|
149
195
|
{
|
|
150
196
|
"opcode": "cameraCalibrationErrorCode",
|
|
151
|
-
"feature": "cameraCalibrationV1",
|
|
152
197
|
"blockType": "REPORTER",
|
|
153
198
|
"text": "camera [CAMERA_ID] calibration error code",
|
|
154
199
|
"description": "Returns a stable code for dependency, board, camera, sample, solve, reprojection, profile, or publication errors, or an empty string.",
|
|
155
200
|
"arguments": {
|
|
156
|
-
"CAMERA_ID": {
|
|
201
|
+
"CAMERA_ID": {
|
|
202
|
+
"type": "STRING",
|
|
203
|
+
"defaultValue": "default"
|
|
204
|
+
}
|
|
157
205
|
}
|
|
158
206
|
},
|
|
159
207
|
{
|
|
160
208
|
"opcode": "cameraCalibrationError",
|
|
161
|
-
"feature": "cameraCalibrationV1",
|
|
162
209
|
"blockType": "REPORTER",
|
|
163
210
|
"text": "camera [CAMERA_ID] calibration error",
|
|
164
211
|
"description": "Returns the detailed calibration diagnostic for that camera.",
|
|
165
212
|
"arguments": {
|
|
166
|
-
"CAMERA_ID": {
|
|
213
|
+
"CAMERA_ID": {
|
|
214
|
+
"type": "STRING",
|
|
215
|
+
"defaultValue": "default"
|
|
216
|
+
}
|
|
167
217
|
}
|
|
168
218
|
},
|
|
169
219
|
{
|
|
170
220
|
"opcode": "cameraCalibrationJson",
|
|
171
|
-
"feature": "cameraCalibrationV1",
|
|
172
221
|
"blockType": "REPORTER",
|
|
173
222
|
"text": "camera [CAMERA_ID] calibration profile JSON",
|
|
174
223
|
"description": "Exports the stored intrinsic profile for that camera, or an empty string when none exists.",
|
|
175
224
|
"arguments": {
|
|
176
|
-
"CAMERA_ID": {
|
|
225
|
+
"CAMERA_ID": {
|
|
226
|
+
"type": "STRING",
|
|
227
|
+
"defaultValue": "default"
|
|
228
|
+
}
|
|
177
229
|
}
|
|
178
230
|
}
|
|
179
231
|
]
|
package/src/extension.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {featureFlags} from '../config/feature-flags.js';
|
|
2
1
|
import {extensionConfig} from './config';
|
|
3
2
|
import definitions from './block-definitions.json';
|
|
4
3
|
import {CameraCalibrationController} from './calibration/controller.js';
|
|
@@ -12,7 +11,6 @@ import {
|
|
|
12
11
|
|
|
13
12
|
type BlockTypeName = 'COMMAND' | 'REPORTER' | 'BOOLEAN';
|
|
14
13
|
type ArgumentTypeName = 'STRING' | 'NUMBER';
|
|
15
|
-
type BlockFeature = 'always' | 'cameraCalibrationV1';
|
|
16
14
|
|
|
17
15
|
interface DefinitionArgument {
|
|
18
16
|
type: ArgumentTypeName;
|
|
@@ -21,7 +19,6 @@ interface DefinitionArgument {
|
|
|
21
19
|
|
|
22
20
|
interface BlockDefinition {
|
|
23
21
|
opcode: string;
|
|
24
|
-
feature: BlockFeature;
|
|
25
22
|
blockType: BlockTypeName;
|
|
26
23
|
text: string;
|
|
27
24
|
description: string;
|
|
@@ -31,7 +28,6 @@ interface BlockDefinition {
|
|
|
31
28
|
export interface CameraCalibrationExtensionOptions {
|
|
32
29
|
runtime?: TurboWarpRuntime;
|
|
33
30
|
backend?: CalibrationBackendFactory;
|
|
34
|
-
enabled?: boolean;
|
|
35
31
|
nowMilliseconds?: () => number;
|
|
36
32
|
}
|
|
37
33
|
|
|
@@ -49,22 +45,17 @@ function normalizeId(value: unknown, fallback = defaultCameraId): string {
|
|
|
49
45
|
export class CameraCalibrationExtension implements TurboWarpExtension {
|
|
50
46
|
private readonly controller: CameraCalibrationController;
|
|
51
47
|
private readonly runtime: TurboWarpRuntime;
|
|
52
|
-
private readonly enabled: boolean;
|
|
53
48
|
private capability: CameraCalibrationCapabilityV1 | undefined;
|
|
54
49
|
|
|
55
50
|
public constructor(options: CameraCalibrationExtensionOptions = {}) {
|
|
56
51
|
this.runtime = options.runtime ?? Scratch.vm.runtime;
|
|
57
|
-
this.enabled = options.enabled ?? featureFlags.cameraCalibrationV1;
|
|
58
52
|
const nowMilliseconds = options.nowMilliseconds;
|
|
59
53
|
this.controller = new CameraCalibrationController({
|
|
60
54
|
runtime: this.runtime,
|
|
61
55
|
backend: options.backend ?? openCvBackendFactory,
|
|
62
56
|
...(nowMilliseconds ? {nowMilliseconds} : {})
|
|
63
57
|
});
|
|
64
|
-
|
|
65
|
-
// the extension will refuse to run has been told the wrong thing, and the
|
|
66
|
-
// refusal would arrive after the operator is already holding the board.
|
|
67
|
-
if (this.enabled) this.runtime[runtimeCapabilityKey] = this.createCapability();
|
|
58
|
+
this.runtime[runtimeCapabilityKey] = this.createCapability();
|
|
68
59
|
this.runtime.on?.('PROJECT_STOP_ALL', this.handleProjectBoundary);
|
|
69
60
|
this.runtime.on?.('PROJECT_LOADED', this.handleProjectBoundary);
|
|
70
61
|
this.runtime.on?.('RUNTIME_DISPOSED', this.handleDisposed);
|
|
@@ -76,9 +67,7 @@ export class CameraCalibrationExtension implements TurboWarpExtension {
|
|
|
76
67
|
name: Scratch.translate(definitions.extensionName),
|
|
77
68
|
docsURI: extensionConfig.docsURI,
|
|
78
69
|
blockIconURI: extensionConfig.blockIconURI,
|
|
79
|
-
blocks: blockDefinitions
|
|
80
|
-
.filter((block) => this.blockEnabled(block.feature))
|
|
81
|
-
.map((block) => this.toScratchBlock(block))
|
|
70
|
+
blocks: blockDefinitions.map((block) => this.toScratchBlock(block))
|
|
82
71
|
};
|
|
83
72
|
}
|
|
84
73
|
|
|
@@ -90,7 +79,6 @@ export class CameraCalibrationExtension implements TurboWarpExtension {
|
|
|
90
79
|
SQUARE_METERS: unknown;
|
|
91
80
|
MAX_ERROR_PX: unknown;
|
|
92
81
|
}): Promise<void> {
|
|
93
|
-
this.requireEnabled();
|
|
94
82
|
await this.controller.start({
|
|
95
83
|
cameraId: normalizeId(args.CAMERA_ID),
|
|
96
84
|
calibrationId: Scratch.Cast.toString(args.CALIBRATION_ID).trim(),
|
|
@@ -104,12 +92,10 @@ export class CameraCalibrationExtension implements TurboWarpExtension {
|
|
|
104
92
|
}
|
|
105
93
|
|
|
106
94
|
public async addCameraCalibrationSample(args: {CAMERA_ID: unknown}): Promise<void> {
|
|
107
|
-
this.requireEnabled();
|
|
108
95
|
await this.controller.addSample(normalizeId(args.CAMERA_ID));
|
|
109
96
|
}
|
|
110
97
|
|
|
111
98
|
public async solveCameraCalibration(args: {CAMERA_ID: unknown}): Promise<void> {
|
|
112
|
-
this.requireEnabled();
|
|
113
99
|
await this.controller.solve(normalizeId(args.CAMERA_ID));
|
|
114
100
|
}
|
|
115
101
|
|
|
@@ -122,7 +108,6 @@ export class CameraCalibrationExtension implements TurboWarpExtension {
|
|
|
122
108
|
}
|
|
123
109
|
|
|
124
110
|
public async publishCameraCalibration(args: {CAMERA_ID: unknown}): Promise<void> {
|
|
125
|
-
this.requireEnabled();
|
|
126
111
|
await this.controller.publishProfile(normalizeId(args.CAMERA_ID));
|
|
127
112
|
}
|
|
128
113
|
|
|
@@ -130,7 +115,6 @@ export class CameraCalibrationExtension implements TurboWarpExtension {
|
|
|
130
115
|
JSON: unknown;
|
|
131
116
|
CAMERA_ID: unknown;
|
|
132
117
|
}): Promise<void> {
|
|
133
|
-
this.requireEnabled();
|
|
134
118
|
await this.controller.importProfile(
|
|
135
119
|
normalizeId(args.CAMERA_ID),
|
|
136
120
|
Scratch.Cast.toString(args.JSON)
|
|
@@ -138,7 +122,6 @@ export class CameraCalibrationExtension implements TurboWarpExtension {
|
|
|
138
122
|
}
|
|
139
123
|
|
|
140
124
|
public cameraCalibrationJsonValid(args: {JSON: unknown; CAMERA_ID: unknown}): boolean {
|
|
141
|
-
if (!this.enabled) return false;
|
|
142
125
|
return this.controller.validateProfile(
|
|
143
126
|
normalizeId(args.CAMERA_ID),
|
|
144
127
|
Scratch.Cast.toString(args.JSON)
|
|
@@ -146,42 +129,39 @@ export class CameraCalibrationExtension implements TurboWarpExtension {
|
|
|
146
129
|
}
|
|
147
130
|
|
|
148
131
|
public cameraCalibrationReady(args: {CAMERA_ID: unknown}): boolean {
|
|
149
|
-
return this.
|
|
132
|
+
return this.controller.ready(normalizeId(args.CAMERA_ID));
|
|
150
133
|
}
|
|
151
134
|
|
|
152
135
|
public cameraCalibrationState(args: {CAMERA_ID?: unknown} = {}): string {
|
|
153
|
-
if (!this.enabled) return IDLE_CALIBRATION_STATE;
|
|
154
136
|
return this.controller.state(normalizeId(args.CAMERA_ID));
|
|
155
137
|
}
|
|
156
138
|
|
|
157
139
|
public cameraCalibrationBackend(): string {
|
|
158
|
-
return this.
|
|
140
|
+
return this.controller.backend();
|
|
159
141
|
}
|
|
160
142
|
|
|
161
143
|
public cameraCalibrationSampleCount(args: {CAMERA_ID: unknown}): number {
|
|
162
|
-
return this.
|
|
144
|
+
return this.controller.sampleCount(normalizeId(args.CAMERA_ID));
|
|
163
145
|
}
|
|
164
146
|
|
|
165
147
|
public cameraCalibrationSampleQuality(args: {CAMERA_ID: unknown}): number {
|
|
166
|
-
return this.
|
|
148
|
+
return this.controller.latestSampleQuality(normalizeId(args.CAMERA_ID));
|
|
167
149
|
}
|
|
168
150
|
|
|
169
151
|
public cameraCalibrationReprojectionError(args: {CAMERA_ID: unknown}): number {
|
|
170
|
-
return this.
|
|
171
|
-
? this.controller.latestReprojectionError(normalizeId(args.CAMERA_ID))
|
|
172
|
-
: 0;
|
|
152
|
+
return this.controller.latestReprojectionError(normalizeId(args.CAMERA_ID));
|
|
173
153
|
}
|
|
174
154
|
|
|
175
155
|
public cameraCalibrationErrorCode(args: {CAMERA_ID: unknown}): string {
|
|
176
|
-
return this.
|
|
156
|
+
return this.controller.errorCode(normalizeId(args.CAMERA_ID));
|
|
177
157
|
}
|
|
178
158
|
|
|
179
159
|
public cameraCalibrationError(args: {CAMERA_ID: unknown}): string {
|
|
180
|
-
return this.
|
|
160
|
+
return this.controller.errorMessage(normalizeId(args.CAMERA_ID));
|
|
181
161
|
}
|
|
182
162
|
|
|
183
163
|
public cameraCalibrationJson(args: {CAMERA_ID: unknown}): string {
|
|
184
|
-
return this.
|
|
164
|
+
return this.controller.profileJson(normalizeId(args.CAMERA_ID));
|
|
185
165
|
}
|
|
186
166
|
|
|
187
167
|
/** Releases every camera lease when the project stops or is replaced. */
|
|
@@ -233,18 +213,6 @@ export class CameraCalibrationExtension implements TurboWarpExtension {
|
|
|
233
213
|
return this.capability;
|
|
234
214
|
}
|
|
235
215
|
|
|
236
|
-
private blockEnabled(feature: BlockFeature): boolean {
|
|
237
|
-
return feature === 'always' || this.enabled;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
private requireEnabled(): void {
|
|
241
|
-
if (!this.enabled) {
|
|
242
|
-
throw new Error(
|
|
243
|
-
'Camera calibration v1 is disabled. Enable it before the project starts.'
|
|
244
|
-
);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
216
|
private toScratchBlock(block: BlockDefinition): Record<string, unknown> {
|
|
249
217
|
return {
|
|
250
218
|
opcode: block.opcode,
|