@kubohiroya/turbowarp-camera-calibration 0.8.2 → 0.9.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 +2 -2
- package/README.md +22 -2
- package/dist/camera-calibration.js +119 -2
- package/dist/extension-manifest.json +20 -0
- package/lib/calibration/contract.d.ts +13 -0
- package/lib/runtime-capability.d.ts +24 -2
- package/lib/runtime-capability.js +3 -1
- package/lib/runtime.d.ts +1 -1
- package/package.json +1 -1
- package/src/block-definitions.json +24 -0
- package/src/calibration/contract.ts +14 -0
- package/src/calibration/controller.ts +58 -3
- package/src/calibration/pose.ts +54 -0
- package/src/extension.ts +10 -0
- package/src/runtime-capability.ts +27 -2
- package/src/runtime.ts +2 -1
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.9.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.9.0/dist/camera-calibration.js
|
|
117
117
|
```
|
|
118
118
|
|
|
119
119
|
## クイックスタート
|
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.9.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.9.0/dist/camera-calibration.js
|
|
118
118
|
```
|
|
119
119
|
|
|
120
120
|
## Quick start
|
|
@@ -248,6 +248,26 @@ Returns what the operator should do next while automatic capture runs: show-the-
|
|
|
248
248
|
| Opcode | `cameraCalibrationGuidance` |
|
|
249
249
|
| `CAMERA_ID` | String, default: `default` |
|
|
250
250
|
|
|
251
|
+
### `camera calibration novelty [CAMERA_ID]`
|
|
252
|
+
|
|
253
|
+
Returns how much the view automatic capture is looking at would add, from 0 to 1. One is a view turned as far from every retained view as the whole set is required to spread; zero means nothing usable is in frame. Measured in tilt, not in where the corners landed: sliding the board moves every corner and adds nothing a solve can use. Meant to drive something continuous -- a tone, a bar, a click rate -- because the operator is holding the board and not reading the screen.
|
|
254
|
+
|
|
255
|
+
| Property | Value |
|
|
256
|
+
|---|---|
|
|
257
|
+
| Type | Reporter |
|
|
258
|
+
| Opcode | `cameraCalibrationNovelty` |
|
|
259
|
+
| `CAMERA_ID` | String, default: `default` |
|
|
260
|
+
|
|
261
|
+
### `camera calibration tilt direction [CAMERA_ID]`
|
|
262
|
+
|
|
263
|
+
Returns which way the board still has to be turned: top-near, top-far, left-near, right-near, or empty outside a live session. The direction least represented in what has been collected, so that "tilt it more" -- an instruction the operator has to interpret -- becomes one they can carry out.
|
|
264
|
+
|
|
265
|
+
| Property | Value |
|
|
266
|
+
|---|---|
|
|
267
|
+
| Type | Reporter |
|
|
268
|
+
| Opcode | `cameraCalibrationTiltDirection` |
|
|
269
|
+
| `CAMERA_ID` | String, default: `default` |
|
|
270
|
+
|
|
251
271
|
### `solve calibration for camera [CAMERA_ID]`
|
|
252
272
|
|
|
253
273
|
Solves the intrinsic matrix and distortion coefficients from at least eight accepted samples, then releases the camera lease. No external pose is produced.
|
|
@@ -108,6 +108,26 @@
|
|
|
108
108
|
"defaultValue": "default"
|
|
109
109
|
} }
|
|
110
110
|
},
|
|
111
|
+
{
|
|
112
|
+
"opcode": "cameraCalibrationNovelty",
|
|
113
|
+
"blockType": "REPORTER",
|
|
114
|
+
"text": "camera calibration novelty [CAMERA_ID]",
|
|
115
|
+
"description": "Returns how much the view automatic capture is looking at would add, from 0 to 1. One is a view turned as far from every retained view as the whole set is required to spread; zero means nothing usable is in frame. Measured in tilt, not in where the corners landed: sliding the board moves every corner and adds nothing a solve can use. Meant to drive something continuous -- a tone, a bar, a click rate -- because the operator is holding the board and not reading the screen.",
|
|
116
|
+
"arguments": { "CAMERA_ID": {
|
|
117
|
+
"type": "STRING",
|
|
118
|
+
"defaultValue": "default"
|
|
119
|
+
} }
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"opcode": "cameraCalibrationTiltDirection",
|
|
123
|
+
"blockType": "REPORTER",
|
|
124
|
+
"text": "camera calibration tilt direction [CAMERA_ID]",
|
|
125
|
+
"description": "Returns which way the board still has to be turned: top-near, top-far, left-near, right-near, or empty outside a live session. The direction least represented in what has been collected, so that \"tilt it more\" -- an instruction the operator has to interpret -- becomes one they can carry out.",
|
|
126
|
+
"arguments": { "CAMERA_ID": {
|
|
127
|
+
"type": "STRING",
|
|
128
|
+
"defaultValue": "default"
|
|
129
|
+
} }
|
|
130
|
+
},
|
|
111
131
|
{
|
|
112
132
|
"opcode": "solveCameraCalibration",
|
|
113
133
|
"blockType": "COMMAND",
|
|
@@ -735,6 +755,44 @@
|
|
|
735
755
|
y: 0
|
|
736
756
|
});
|
|
737
757
|
/**
|
|
758
|
+
* Which way the board still has to be turned.
|
|
759
|
+
*
|
|
760
|
+
* `x` is the upper half's grid steps against the lower half's, so a positive
|
|
761
|
+
* `x` is a board whose top is nearer the camera. `y` is the left half against
|
|
762
|
+
* the right, so a positive `y` is a board whose left edge is nearer. The names
|
|
763
|
+
* are in the contract; the signs they correspond to are here.
|
|
764
|
+
*/
|
|
765
|
+
/**
|
|
766
|
+
* The direction least represented in what has been collected.
|
|
767
|
+
*
|
|
768
|
+
* Each direction is scored by the furthest any held view reaches along it, and
|
|
769
|
+
* the weakest wins. Asking for the weakest rather than simply "more tilt"
|
|
770
|
+
* turns an instruction the operator has to interpret into one they can carry
|
|
771
|
+
* out, and it spreads the set on purpose rather than by luck.
|
|
772
|
+
*
|
|
773
|
+
* Nothing collected asks for the first direction rather than nothing at all:
|
|
774
|
+
* an operator holding a board square-on has to be told to start somewhere.
|
|
775
|
+
*/
|
|
776
|
+
function weakestTiltDirection(samples, board) {
|
|
777
|
+
const tilts = samples.map((sample) => tiltOf(sample, board));
|
|
778
|
+
const reach = [
|
|
779
|
+
["top-near", (tilt) => tilt.x],
|
|
780
|
+
["top-far", (tilt) => -tilt.x],
|
|
781
|
+
["left-near", (tilt) => tilt.y],
|
|
782
|
+
["right-near", (tilt) => -tilt.y]
|
|
783
|
+
];
|
|
784
|
+
let weakest = "top-near";
|
|
785
|
+
let smallest = Number.POSITIVE_INFINITY;
|
|
786
|
+
for (const [direction, along] of reach) {
|
|
787
|
+
const furthest = tilts.reduce((best, tilt) => Math.max(best, along(tilt)), 0);
|
|
788
|
+
if (furthest < smallest) {
|
|
789
|
+
smallest = furthest;
|
|
790
|
+
weakest = direction;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
return weakest;
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
738
796
|
* The minimum spread of tilts a solve is allowed to proceed from.
|
|
739
797
|
*
|
|
740
798
|
* A board half as wide as its distance, tilted thirty degrees, gives an edge
|
|
@@ -743,6 +801,16 @@
|
|
|
743
801
|
* way every time, without refusing a cautious operator who varied it a little.
|
|
744
802
|
*/
|
|
745
803
|
var MINIMUM_POSE_SPREAD = .08;
|
|
804
|
+
/**
|
|
805
|
+
* How differently two views were turned.
|
|
806
|
+
*
|
|
807
|
+
* The distance the solve cares about. Two views taken from the same angle
|
|
808
|
+
* constrain the same thing however far apart on the board they were taken, so
|
|
809
|
+
* this ignores where the board was and reads only how it was turned.
|
|
810
|
+
*/
|
|
811
|
+
function tiltDistance(left, right) {
|
|
812
|
+
return Math.hypot(left.x - right.x, left.y - right.y);
|
|
813
|
+
}
|
|
746
814
|
function tiltOf(sample, board) {
|
|
747
815
|
const { columns, rows } = board;
|
|
748
816
|
const at = /* @__PURE__ */ new Map();
|
|
@@ -893,6 +961,7 @@
|
|
|
893
961
|
this.operation = 0;
|
|
894
962
|
this.automatic = false;
|
|
895
963
|
this.guidanceCode = "";
|
|
964
|
+
this.noveltyNow = 0;
|
|
896
965
|
this.solvedFrom = 0;
|
|
897
966
|
}
|
|
898
967
|
async start(options) {
|
|
@@ -996,6 +1065,14 @@
|
|
|
996
1065
|
guidance() {
|
|
997
1066
|
return this.guidanceCode;
|
|
998
1067
|
}
|
|
1068
|
+
novelty() {
|
|
1069
|
+
return this.noveltyNow;
|
|
1070
|
+
}
|
|
1071
|
+
/** Which way to turn the board next. Empty outside a live session. */
|
|
1072
|
+
tiltDirection() {
|
|
1073
|
+
if (!this.session || !this.lease) return "";
|
|
1074
|
+
return weakestTiltDirection(this.samples, this.session.board);
|
|
1075
|
+
}
|
|
999
1076
|
/**
|
|
1000
1077
|
* Waits for the camera to hand over a frame with a size on it.
|
|
1001
1078
|
*
|
|
@@ -1022,6 +1099,7 @@
|
|
|
1022
1099
|
}
|
|
1023
1100
|
stopAutomatic() {
|
|
1024
1101
|
this.automatic = false;
|
|
1102
|
+
this.noveltyNow = 0;
|
|
1025
1103
|
this.cancelTick?.();
|
|
1026
1104
|
this.cancelTick = void 0;
|
|
1027
1105
|
}
|
|
@@ -1339,6 +1417,7 @@
|
|
|
1339
1417
|
if (operation !== this.operation) return;
|
|
1340
1418
|
const sample = detection.sample;
|
|
1341
1419
|
if (!sample) {
|
|
1420
|
+
this.noveltyNow = 0;
|
|
1342
1421
|
const elsewhere = detection.markersSeen > 0;
|
|
1343
1422
|
if (automatic) return this.decline(elsewhere ? "wrong-board" : "show-the-board");
|
|
1344
1423
|
if (elsewhere) this.reject("wrong-board", `${detection.markersSeen} markers are in frame and they do not make the ${session.board.columns}x${session.board.rows} board. Show that board, or start again with the one you are holding.`);
|
|
@@ -1349,6 +1428,7 @@
|
|
|
1349
1428
|
this.reject("sample-low-quality", `Sample quality must be at least ${MINIMUM_SAMPLE_QUALITY}.`);
|
|
1350
1429
|
}
|
|
1351
1430
|
const accepted = sample;
|
|
1431
|
+
this.noveltyNow = this.noveltyOf(accepted, session);
|
|
1352
1432
|
if (this.samples.some((previous) => normalizedCornerDistance(previous, accepted, session.imageWidth, session.imageHeight) < MINIMUM_NORMALIZED_NOVELTY)) {
|
|
1353
1433
|
if (automatic) return this.decline("move-or-tilt");
|
|
1354
1434
|
this.reject("sample-too-similar", "Move or tilt the board before capturing another sample.");
|
|
@@ -1393,6 +1473,27 @@
|
|
|
1393
1473
|
}
|
|
1394
1474
|
this.samples.splice(dullest, 1);
|
|
1395
1475
|
}
|
|
1476
|
+
/**
|
|
1477
|
+
* How much the view being looked at would add, from 0 to 1.
|
|
1478
|
+
*
|
|
1479
|
+
* Measured in tilt, not in where the corners landed. The corner distance is
|
|
1480
|
+
* what decides whether a view is a duplicate, and it is deliberately not
|
|
1481
|
+
* this: sliding the board across the frame moves every corner a long way and
|
|
1482
|
+
* adds nothing a solve can use, so a signal driven by it would be loudest
|
|
1483
|
+
* for the one motion that does not work. Tilt is what separates focal length
|
|
1484
|
+
* from distance, so tilt is what this rewards.
|
|
1485
|
+
*
|
|
1486
|
+
* One is a view turned as far from everything held as the whole set is
|
|
1487
|
+
* required to spread, which is a view worth stopping for. An empty set reads
|
|
1488
|
+
* as one, because the first view is the most useful one there is.
|
|
1489
|
+
*/
|
|
1490
|
+
noveltyOf(sample, session) {
|
|
1491
|
+
if (this.samples.length === 0) return 1;
|
|
1492
|
+
const tilt = tiltOf(sample, session.board);
|
|
1493
|
+
let nearest = Number.POSITIVE_INFINITY;
|
|
1494
|
+
for (const held of this.samples) nearest = Math.min(nearest, tiltDistance(tilt, tiltOf(held, session.board)));
|
|
1495
|
+
return Math.max(0, Math.min(1, nearest / MINIMUM_POSE_SPREAD));
|
|
1496
|
+
}
|
|
1396
1497
|
/** Records what the operator should do next, without disturbing the state. */
|
|
1397
1498
|
guide(guidance) {
|
|
1398
1499
|
this.guidanceCode = guidance;
|
|
@@ -1557,6 +1658,12 @@
|
|
|
1557
1658
|
guidance(cameraId) {
|
|
1558
1659
|
return this.existing(cameraId)?.guidance() ?? "";
|
|
1559
1660
|
}
|
|
1661
|
+
novelty(cameraId) {
|
|
1662
|
+
return this.existing(cameraId)?.novelty() ?? 0;
|
|
1663
|
+
}
|
|
1664
|
+
tiltDirection(cameraId) {
|
|
1665
|
+
return this.existing(cameraId)?.tiltDirection() ?? "";
|
|
1666
|
+
}
|
|
1560
1667
|
cancel(cameraId) {
|
|
1561
1668
|
return this.existing(cameraId)?.cancel() ?? Promise.resolve();
|
|
1562
1669
|
}
|
|
@@ -2100,9 +2207,9 @@
|
|
|
2100
2207
|
var runtimeCapabilityKey = "kubohiroyaCameraCalibrationCapability";
|
|
2101
2208
|
function createRuntimeCapability(host) {
|
|
2102
2209
|
const capability = {
|
|
2103
|
-
version:
|
|
2210
|
+
version: 3,
|
|
2104
2211
|
requireVersion(version) {
|
|
2105
|
-
if (!Number.isInteger(version) || version < 1 || version >
|
|
2212
|
+
if (!Number.isInteger(version) || version < 1 || version > 3) throw new Error(`Unsupported Camera Calibration runtime capability version: ${version}; this build provides 3.`);
|
|
2106
2213
|
return capability;
|
|
2107
2214
|
},
|
|
2108
2215
|
start: (options) => host.start(options),
|
|
@@ -2110,6 +2217,8 @@
|
|
|
2110
2217
|
setAutomatic: (cameraId, enabled) => host.setAutomatic(cameraId, enabled),
|
|
2111
2218
|
automatic: (cameraId) => host.automatic(cameraId),
|
|
2112
2219
|
guidance: (cameraId) => host.guidance(cameraId),
|
|
2220
|
+
novelty: (cameraId) => host.novelty(cameraId),
|
|
2221
|
+
tiltDirection: (cameraId) => host.tiltDirection(cameraId),
|
|
2113
2222
|
solve: (cameraId) => host.solve(cameraId),
|
|
2114
2223
|
publish: (cameraId) => host.publish(cameraId),
|
|
2115
2224
|
cancel: (cameraId) => host.cancel(cameraId),
|
|
@@ -2211,6 +2320,12 @@
|
|
|
2211
2320
|
cameraCalibrationGuidance(args) {
|
|
2212
2321
|
return this.controller.guidance(normalizeId(args.CAMERA_ID));
|
|
2213
2322
|
}
|
|
2323
|
+
cameraCalibrationNovelty(args) {
|
|
2324
|
+
return this.controller.novelty(normalizeId(args.CAMERA_ID));
|
|
2325
|
+
}
|
|
2326
|
+
cameraCalibrationTiltDirection(args) {
|
|
2327
|
+
return this.controller.tiltDirection(normalizeId(args.CAMERA_ID));
|
|
2328
|
+
}
|
|
2214
2329
|
async solveCameraCalibration(args) {
|
|
2215
2330
|
await this.controller.solve(normalizeId(args.CAMERA_ID));
|
|
2216
2331
|
}
|
|
@@ -2297,6 +2412,8 @@
|
|
|
2297
2412
|
setAutomatic: (cameraId, enabled) => this.controller.setAutomatic(normalizeId(cameraId), enabled),
|
|
2298
2413
|
automatic: (cameraId) => this.controller.automatic(normalizeId(cameraId)),
|
|
2299
2414
|
guidance: (cameraId) => this.controller.guidance(normalizeId(cameraId)),
|
|
2415
|
+
novelty: (cameraId) => this.controller.novelty(normalizeId(cameraId)),
|
|
2416
|
+
tiltDirection: (cameraId) => this.controller.tiltDirection(normalizeId(cameraId)),
|
|
2300
2417
|
solve: (cameraId) => this.controller.solve(normalizeId(cameraId)),
|
|
2301
2418
|
publish: (cameraId) => this.controller.publishProfile(normalizeId(cameraId)),
|
|
2302
2419
|
cancel: (cameraId) => this.controller.cancel(normalizeId(cameraId)),
|
|
@@ -111,6 +111,16 @@
|
|
|
111
111
|
}
|
|
112
112
|
]
|
|
113
113
|
},
|
|
114
|
+
{
|
|
115
|
+
"opcode": "cameraCalibrationNovelty",
|
|
116
|
+
"blockType": "REPORTER",
|
|
117
|
+
"arguments": [
|
|
118
|
+
{
|
|
119
|
+
"id": "CAMERA_ID",
|
|
120
|
+
"type": "STRING"
|
|
121
|
+
}
|
|
122
|
+
]
|
|
123
|
+
},
|
|
114
124
|
{
|
|
115
125
|
"opcode": "cameraCalibrationPoseSpread",
|
|
116
126
|
"blockType": "REPORTER",
|
|
@@ -171,6 +181,16 @@
|
|
|
171
181
|
}
|
|
172
182
|
]
|
|
173
183
|
},
|
|
184
|
+
{
|
|
185
|
+
"opcode": "cameraCalibrationTiltDirection",
|
|
186
|
+
"blockType": "REPORTER",
|
|
187
|
+
"arguments": [
|
|
188
|
+
{
|
|
189
|
+
"id": "CAMERA_ID",
|
|
190
|
+
"type": "STRING"
|
|
191
|
+
}
|
|
192
|
+
]
|
|
193
|
+
},
|
|
174
194
|
{
|
|
175
195
|
"opcode": "cancelCameraCalibration",
|
|
176
196
|
"blockType": "COMMAND",
|
|
@@ -60,6 +60,19 @@ export type CalibrationGuidance = ''
|
|
|
60
60
|
| 'solving'
|
|
61
61
|
/** Solved and validated. Nothing further is needed. */
|
|
62
62
|
| 'complete';
|
|
63
|
+
/**
|
|
64
|
+
* Which way the board still has to be turned.
|
|
65
|
+
*
|
|
66
|
+
* Two axes, one sign at a time. `top-near` and `top-far` turn it about the
|
|
67
|
+
* horizontal axis; `left-near` and `right-near` about the vertical one. That
|
|
68
|
+
* is as much as can be said without knowing where the operator is standing,
|
|
69
|
+
* and as much as they need, since they are looking at the same board.
|
|
70
|
+
*
|
|
71
|
+
* Here rather than beside the arithmetic that works it out, because the
|
|
72
|
+
* published entry carries declarations and nothing else: a consumer asking
|
|
73
|
+
* what the names mean must not pull in the measuring.
|
|
74
|
+
*/
|
|
75
|
+
export type TiltDirection = '' | 'top-near' | 'top-far' | 'left-near' | 'right-near';
|
|
63
76
|
/**
|
|
64
77
|
* Where the scale of a measured pose came from.
|
|
65
78
|
*
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
* finding a method missing partway through a calibration the operator is
|
|
13
13
|
* already standing in front of.
|
|
14
14
|
*/
|
|
15
|
-
import type { BoardPoseOptions, CalibrationErrorCode, CalibrationGuidance, CalibrationStartOptions, CalibrationState } from './calibration/contract.js';
|
|
15
|
+
import type { BoardPoseOptions, CalibrationErrorCode, CalibrationGuidance, CalibrationStartOptions, CalibrationState, TiltDirection } from './calibration/contract.js';
|
|
16
16
|
export declare const runtimeCapabilityKey = "kubohiroyaCameraCalibrationCapability";
|
|
17
|
-
export declare const runtimeCapabilityVersion:
|
|
17
|
+
export declare const runtimeCapabilityVersion: 3;
|
|
18
18
|
export interface CameraCalibrationCapabilityV1 {
|
|
19
19
|
readonly version: typeof runtimeCapabilityVersion;
|
|
20
20
|
requireVersion(version: number): CameraCalibrationCapabilityV1;
|
|
@@ -49,6 +49,28 @@ export interface CameraCalibrationCapabilityV1 {
|
|
|
49
49
|
* recording those as errors would leave one showing for most of a session.
|
|
50
50
|
*/
|
|
51
51
|
guidance(cameraId: string): CalibrationGuidance;
|
|
52
|
+
/**
|
|
53
|
+
* How much the view the shutter is looking at would add, 0 to 1. Since v3.
|
|
54
|
+
*
|
|
55
|
+
* Measured in tilt rather than in where the corners landed: sliding the
|
|
56
|
+
* board moves every corner and adds nothing a solve can use, so a signal
|
|
57
|
+
* driven by corner distance would be loudest for the one motion that does
|
|
58
|
+
* not work. One is a view turned as far from everything held as the whole
|
|
59
|
+
* set is required to spread. Zero when nothing usable is in frame.
|
|
60
|
+
*
|
|
61
|
+
* Meant for something continuous -- a tone, a bar, a click rate -- because
|
|
62
|
+
* the operator is holding the board and not reading the screen.
|
|
63
|
+
*/
|
|
64
|
+
novelty(cameraId: string): number;
|
|
65
|
+
/**
|
|
66
|
+
* Which way the board still has to be turned. Since v3.
|
|
67
|
+
*
|
|
68
|
+
* `top-near`, `top-far`, `left-near`, `right-near`, or empty outside a live
|
|
69
|
+
* session. The direction least represented in what has been collected, so
|
|
70
|
+
* that "tilt it more" -- an instruction the operator has to interpret --
|
|
71
|
+
* becomes one they can carry out.
|
|
72
|
+
*/
|
|
73
|
+
tiltDirection(cameraId: string): TiltDirection;
|
|
52
74
|
/** Solves from the accepted samples and releases the camera. */
|
|
53
75
|
solve(cameraId: string): Promise<void>;
|
|
54
76
|
/** Hands the solved profile to Camera Source, which owns the profile contract. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const runtimeCapabilityKey = 'kubohiroyaCameraCalibrationCapability';
|
|
2
|
-
export const runtimeCapabilityVersion =
|
|
2
|
+
export const runtimeCapabilityVersion = 3;
|
|
3
3
|
export function createRuntimeCapability(host) {
|
|
4
4
|
const capability = {
|
|
5
5
|
version: runtimeCapabilityVersion,
|
|
@@ -20,6 +20,8 @@ export function createRuntimeCapability(host) {
|
|
|
20
20
|
setAutomatic: (cameraId, enabled) => host.setAutomatic(cameraId, enabled),
|
|
21
21
|
automatic: (cameraId) => host.automatic(cameraId),
|
|
22
22
|
guidance: (cameraId) => host.guidance(cameraId),
|
|
23
|
+
novelty: (cameraId) => host.novelty(cameraId),
|
|
24
|
+
tiltDirection: (cameraId) => host.tiltDirection(cameraId),
|
|
23
25
|
solve: (cameraId) => host.solve(cameraId),
|
|
24
26
|
publish: (cameraId) => host.publish(cameraId),
|
|
25
27
|
cancel: (cameraId) => host.cancel(cameraId),
|
package/lib/runtime.d.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* every attempt to publish a profile failed with a version mismatch that had
|
|
16
16
|
* nothing to do with versions.
|
|
17
17
|
*/
|
|
18
|
-
export type { CalibrationErrorCode, CalibrationGuidance, CalibrationStartOptions, CalibrationState } from './calibration/contract.js';
|
|
18
|
+
export type { CalibrationErrorCode, CalibrationGuidance, CalibrationStartOptions, CalibrationState, TiltDirection } from './calibration/contract.js';
|
|
19
19
|
export type { CalibrationBoard } from './calibration/types.js';
|
|
20
20
|
export { createRuntimeCapability, runtimeCapabilityKey, runtimeCapabilityVersion, type CameraCalibrationCapabilityV1 } from './runtime-capability.js';
|
|
21
21
|
import { type CameraCalibrationCapabilityV1 } from './runtime-capability.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-camera-calibration",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.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",
|
|
@@ -97,6 +97,30 @@
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
},
|
|
100
|
+
{
|
|
101
|
+
"opcode": "cameraCalibrationNovelty",
|
|
102
|
+
"blockType": "REPORTER",
|
|
103
|
+
"text": "camera calibration novelty [CAMERA_ID]",
|
|
104
|
+
"description": "Returns how much the view automatic capture is looking at would add, from 0 to 1. One is a view turned as far from every retained view as the whole set is required to spread; zero means nothing usable is in frame. Measured in tilt, not in where the corners landed: sliding the board moves every corner and adds nothing a solve can use. Meant to drive something continuous -- a tone, a bar, a click rate -- because the operator is holding the board and not reading the screen.",
|
|
105
|
+
"arguments": {
|
|
106
|
+
"CAMERA_ID": {
|
|
107
|
+
"type": "STRING",
|
|
108
|
+
"defaultValue": "default"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"opcode": "cameraCalibrationTiltDirection",
|
|
114
|
+
"blockType": "REPORTER",
|
|
115
|
+
"text": "camera calibration tilt direction [CAMERA_ID]",
|
|
116
|
+
"description": "Returns which way the board still has to be turned: top-near, top-far, left-near, right-near, or empty outside a live session. The direction least represented in what has been collected, so that \"tilt it more\" -- an instruction the operator has to interpret -- becomes one they can carry out.",
|
|
117
|
+
"arguments": {
|
|
118
|
+
"CAMERA_ID": {
|
|
119
|
+
"type": "STRING",
|
|
120
|
+
"defaultValue": "default"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
},
|
|
100
124
|
{
|
|
101
125
|
"opcode": "solveCameraCalibration",
|
|
102
126
|
"blockType": "COMMAND",
|
|
@@ -97,6 +97,20 @@ export type CalibrationGuidance =
|
|
|
97
97
|
/** Solved and validated. Nothing further is needed. */
|
|
98
98
|
| 'complete';
|
|
99
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Which way the board still has to be turned.
|
|
102
|
+
*
|
|
103
|
+
* Two axes, one sign at a time. `top-near` and `top-far` turn it about the
|
|
104
|
+
* horizontal axis; `left-near` and `right-near` about the vertical one. That
|
|
105
|
+
* is as much as can be said without knowing where the operator is standing,
|
|
106
|
+
* and as much as they need, since they are looking at the same board.
|
|
107
|
+
*
|
|
108
|
+
* Here rather than beside the arithmetic that works it out, because the
|
|
109
|
+
* published entry carries declarations and nothing else: a consumer asking
|
|
110
|
+
* what the names mean must not pull in the measuring.
|
|
111
|
+
*/
|
|
112
|
+
export type TiltDirection = '' | 'top-near' | 'top-far' | 'left-near' | 'right-near';
|
|
113
|
+
|
|
100
114
|
/**
|
|
101
115
|
* Where the scale of a measured pose came from.
|
|
102
116
|
*
|
|
@@ -20,16 +20,24 @@ export type {
|
|
|
20
20
|
CalibrationErrorCode,
|
|
21
21
|
CalibrationGuidance,
|
|
22
22
|
CalibrationStartOptions,
|
|
23
|
-
CalibrationState
|
|
23
|
+
CalibrationState,
|
|
24
|
+
TiltDirection
|
|
24
25
|
} from './contract.js';
|
|
25
26
|
import type {
|
|
26
27
|
BoardPoseOptions,
|
|
27
28
|
CalibrationErrorCode,
|
|
28
29
|
CalibrationGuidance,
|
|
29
30
|
CalibrationStartOptions,
|
|
30
|
-
CalibrationState
|
|
31
|
+
CalibrationState,
|
|
32
|
+
TiltDirection
|
|
31
33
|
} from './contract.js';
|
|
32
|
-
import {
|
|
34
|
+
import {
|
|
35
|
+
MINIMUM_POSE_SPREAD,
|
|
36
|
+
poseSpread,
|
|
37
|
+
tiltDistance,
|
|
38
|
+
tiltOf,
|
|
39
|
+
weakestTiltDirection
|
|
40
|
+
} from './pose.js';
|
|
33
41
|
import type {
|
|
34
42
|
CalibrationBackendFactory,
|
|
35
43
|
CalibrationBackendPort,
|
|
@@ -167,6 +175,8 @@ class CameraCalibration {
|
|
|
167
175
|
private automatic = false;
|
|
168
176
|
private cancelTick: (() => void) | undefined;
|
|
169
177
|
private guidanceCode: CalibrationGuidance = '';
|
|
178
|
+
/** How much the view the shutter last looked at would add. */
|
|
179
|
+
private noveltyNow = 0;
|
|
170
180
|
/** Sample count the last automatic solve was started from. */
|
|
171
181
|
private solvedFrom = 0;
|
|
172
182
|
|
|
@@ -294,6 +304,16 @@ class CameraCalibration {
|
|
|
294
304
|
return this.guidanceCode;
|
|
295
305
|
}
|
|
296
306
|
|
|
307
|
+
public novelty(): number {
|
|
308
|
+
return this.noveltyNow;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** Which way to turn the board next. Empty outside a live session. */
|
|
312
|
+
public tiltDirection(): TiltDirection {
|
|
313
|
+
if (!this.session || !this.lease) return '';
|
|
314
|
+
return weakestTiltDirection(this.samples, this.session.board);
|
|
315
|
+
}
|
|
316
|
+
|
|
297
317
|
/**
|
|
298
318
|
* Waits for the camera to hand over a frame with a size on it.
|
|
299
319
|
*
|
|
@@ -340,6 +360,7 @@ class CameraCalibration {
|
|
|
340
360
|
|
|
341
361
|
private stopAutomatic(): void {
|
|
342
362
|
this.automatic = false;
|
|
363
|
+
this.noveltyNow = 0;
|
|
343
364
|
this.cancelTick?.();
|
|
344
365
|
this.cancelTick = undefined;
|
|
345
366
|
}
|
|
@@ -808,6 +829,7 @@ class CameraCalibration {
|
|
|
808
829
|
// one of them means fetch the other sheet. Told to "show the board"
|
|
809
830
|
// while holding one, they have no reason to think anything but that the
|
|
810
831
|
// camera is broken.
|
|
832
|
+
this.noveltyNow = 0;
|
|
811
833
|
const elsewhere = detection.markersSeen > 0;
|
|
812
834
|
if (automatic) return this.decline(elsewhere ? 'wrong-board' : 'show-the-board');
|
|
813
835
|
if (elsewhere) {
|
|
@@ -831,6 +853,7 @@ class CameraCalibration {
|
|
|
831
853
|
this.reject('sample-low-quality', `Sample quality must be at least ${MINIMUM_SAMPLE_QUALITY}.`);
|
|
832
854
|
}
|
|
833
855
|
const accepted = sample;
|
|
856
|
+
this.noveltyNow = this.noveltyOf(accepted, session);
|
|
834
857
|
if (
|
|
835
858
|
this.samples.some(
|
|
836
859
|
(previous) =>
|
|
@@ -886,6 +909,30 @@ class CameraCalibration {
|
|
|
886
909
|
this.samples.splice(dullest, 1);
|
|
887
910
|
}
|
|
888
911
|
|
|
912
|
+
/**
|
|
913
|
+
* How much the view being looked at would add, from 0 to 1.
|
|
914
|
+
*
|
|
915
|
+
* Measured in tilt, not in where the corners landed. The corner distance is
|
|
916
|
+
* what decides whether a view is a duplicate, and it is deliberately not
|
|
917
|
+
* this: sliding the board across the frame moves every corner a long way and
|
|
918
|
+
* adds nothing a solve can use, so a signal driven by it would be loudest
|
|
919
|
+
* for the one motion that does not work. Tilt is what separates focal length
|
|
920
|
+
* from distance, so tilt is what this rewards.
|
|
921
|
+
*
|
|
922
|
+
* One is a view turned as far from everything held as the whole set is
|
|
923
|
+
* required to spread, which is a view worth stopping for. An empty set reads
|
|
924
|
+
* as one, because the first view is the most useful one there is.
|
|
925
|
+
*/
|
|
926
|
+
private noveltyOf(sample: CalibrationSample, session: CalibrationSession): number {
|
|
927
|
+
if (this.samples.length === 0) return 1;
|
|
928
|
+
const tilt = tiltOf(sample, session.board);
|
|
929
|
+
let nearest = Number.POSITIVE_INFINITY;
|
|
930
|
+
for (const held of this.samples) {
|
|
931
|
+
nearest = Math.min(nearest, tiltDistance(tilt, tiltOf(held, session.board)));
|
|
932
|
+
}
|
|
933
|
+
return Math.max(0, Math.min(1, nearest / MINIMUM_POSE_SPREAD));
|
|
934
|
+
}
|
|
935
|
+
|
|
889
936
|
/** Records what the operator should do next, without disturbing the state. */
|
|
890
937
|
private guide(guidance: CalibrationGuidance): void {
|
|
891
938
|
this.guidanceCode = guidance;
|
|
@@ -1095,6 +1142,14 @@ export class CameraCalibrationController {
|
|
|
1095
1142
|
return this.existing(cameraId)?.guidance() ?? '';
|
|
1096
1143
|
}
|
|
1097
1144
|
|
|
1145
|
+
public novelty(cameraId: string): number {
|
|
1146
|
+
return this.existing(cameraId)?.novelty() ?? 0;
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
public tiltDirection(cameraId: string): TiltDirection {
|
|
1150
|
+
return this.existing(cameraId)?.tiltDirection() ?? '';
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1098
1153
|
public cancel(cameraId: string): Promise<void> {
|
|
1099
1154
|
return this.existing(cameraId)?.cancel() ?? Promise.resolve();
|
|
1100
1155
|
}
|
package/src/calibration/pose.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type {TiltDirection} from './contract.js';
|
|
1
2
|
import type {CalibrationBoard, CalibrationCorner, CalibrationSample} from './types.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -33,6 +34,48 @@ export interface Tilt {
|
|
|
33
34
|
|
|
34
35
|
export const NO_TILT: Tilt = Object.freeze({x: 0, y: 0});
|
|
35
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Which way the board still has to be turned.
|
|
39
|
+
*
|
|
40
|
+
* `x` is the upper half's grid steps against the lower half's, so a positive
|
|
41
|
+
* `x` is a board whose top is nearer the camera. `y` is the left half against
|
|
42
|
+
* the right, so a positive `y` is a board whose left edge is nearer. The names
|
|
43
|
+
* are in the contract; the signs they correspond to are here.
|
|
44
|
+
*/
|
|
45
|
+
/**
|
|
46
|
+
* The direction least represented in what has been collected.
|
|
47
|
+
*
|
|
48
|
+
* Each direction is scored by the furthest any held view reaches along it, and
|
|
49
|
+
* the weakest wins. Asking for the weakest rather than simply "more tilt"
|
|
50
|
+
* turns an instruction the operator has to interpret into one they can carry
|
|
51
|
+
* out, and it spreads the set on purpose rather than by luck.
|
|
52
|
+
*
|
|
53
|
+
* Nothing collected asks for the first direction rather than nothing at all:
|
|
54
|
+
* an operator holding a board square-on has to be told to start somewhere.
|
|
55
|
+
*/
|
|
56
|
+
export function weakestTiltDirection(
|
|
57
|
+
samples: readonly CalibrationSample[],
|
|
58
|
+
board: CalibrationBoard
|
|
59
|
+
): TiltDirection {
|
|
60
|
+
const tilts = samples.map((sample) => tiltOf(sample, board));
|
|
61
|
+
const reach: ReadonlyArray<readonly [TiltDirection, (tilt: Tilt) => number]> = [
|
|
62
|
+
['top-near', (tilt) => tilt.x],
|
|
63
|
+
['top-far', (tilt) => -tilt.x],
|
|
64
|
+
['left-near', (tilt) => tilt.y],
|
|
65
|
+
['right-near', (tilt) => -tilt.y]
|
|
66
|
+
];
|
|
67
|
+
let weakest: TiltDirection = 'top-near';
|
|
68
|
+
let smallest = Number.POSITIVE_INFINITY;
|
|
69
|
+
for (const [direction, along] of reach) {
|
|
70
|
+
const furthest = tilts.reduce((best, tilt) => Math.max(best, along(tilt)), 0);
|
|
71
|
+
if (furthest < smallest) {
|
|
72
|
+
smallest = furthest;
|
|
73
|
+
weakest = direction;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return weakest;
|
|
77
|
+
}
|
|
78
|
+
|
|
36
79
|
/**
|
|
37
80
|
* The minimum spread of tilts a solve is allowed to proceed from.
|
|
38
81
|
*
|
|
@@ -43,6 +86,17 @@ export const NO_TILT: Tilt = Object.freeze({x: 0, y: 0});
|
|
|
43
86
|
*/
|
|
44
87
|
export const MINIMUM_POSE_SPREAD = 0.08;
|
|
45
88
|
|
|
89
|
+
/**
|
|
90
|
+
* How differently two views were turned.
|
|
91
|
+
*
|
|
92
|
+
* The distance the solve cares about. Two views taken from the same angle
|
|
93
|
+
* constrain the same thing however far apart on the board they were taken, so
|
|
94
|
+
* this ignores where the board was and reads only how it was turned.
|
|
95
|
+
*/
|
|
96
|
+
export function tiltDistance(left: Tilt, right: Tilt): number {
|
|
97
|
+
return Math.hypot(left.x - right.x, left.y - right.y);
|
|
98
|
+
}
|
|
99
|
+
|
|
46
100
|
export function tiltOf(sample: CalibrationSample, board: CalibrationBoard): Tilt {
|
|
47
101
|
const {columns, rows} = board;
|
|
48
102
|
const at = new Map<number, CalibrationCorner>();
|
package/src/extension.ts
CHANGED
|
@@ -125,6 +125,14 @@ export class CameraCalibrationExtension implements TurboWarpExtension {
|
|
|
125
125
|
return this.controller.guidance(normalizeId(args.CAMERA_ID));
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
+
public cameraCalibrationNovelty(args: {CAMERA_ID: unknown}): number {
|
|
129
|
+
return this.controller.novelty(normalizeId(args.CAMERA_ID));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public cameraCalibrationTiltDirection(args: {CAMERA_ID: unknown}): string {
|
|
133
|
+
return this.controller.tiltDirection(normalizeId(args.CAMERA_ID));
|
|
134
|
+
}
|
|
135
|
+
|
|
128
136
|
public async solveCameraCalibration(args: {CAMERA_ID: unknown}): Promise<void> {
|
|
129
137
|
await this.controller.solve(normalizeId(args.CAMERA_ID));
|
|
130
138
|
}
|
|
@@ -262,6 +270,8 @@ export class CameraCalibrationExtension implements TurboWarpExtension {
|
|
|
262
270
|
this.controller.setAutomatic(normalizeId(cameraId), enabled),
|
|
263
271
|
automatic: (cameraId) => this.controller.automatic(normalizeId(cameraId)),
|
|
264
272
|
guidance: (cameraId) => this.controller.guidance(normalizeId(cameraId)),
|
|
273
|
+
novelty: (cameraId) => this.controller.novelty(normalizeId(cameraId)),
|
|
274
|
+
tiltDirection: (cameraId) => this.controller.tiltDirection(normalizeId(cameraId)),
|
|
265
275
|
solve: (cameraId) => this.controller.solve(normalizeId(cameraId)),
|
|
266
276
|
publish: (cameraId) => this.controller.publishProfile(normalizeId(cameraId)),
|
|
267
277
|
cancel: (cameraId) => this.controller.cancel(normalizeId(cameraId)),
|
|
@@ -17,11 +17,12 @@ import type {
|
|
|
17
17
|
CalibrationErrorCode,
|
|
18
18
|
CalibrationGuidance,
|
|
19
19
|
CalibrationStartOptions,
|
|
20
|
-
CalibrationState
|
|
20
|
+
CalibrationState,
|
|
21
|
+
TiltDirection
|
|
21
22
|
} from './calibration/contract.js';
|
|
22
23
|
|
|
23
24
|
export const runtimeCapabilityKey = 'kubohiroyaCameraCalibrationCapability';
|
|
24
|
-
export const runtimeCapabilityVersion =
|
|
25
|
+
export const runtimeCapabilityVersion = 3 as const;
|
|
25
26
|
|
|
26
27
|
export interface CameraCalibrationCapabilityV1 {
|
|
27
28
|
readonly version: typeof runtimeCapabilityVersion;
|
|
@@ -58,6 +59,28 @@ export interface CameraCalibrationCapabilityV1 {
|
|
|
58
59
|
* recording those as errors would leave one showing for most of a session.
|
|
59
60
|
*/
|
|
60
61
|
guidance(cameraId: string): CalibrationGuidance;
|
|
62
|
+
/**
|
|
63
|
+
* How much the view the shutter is looking at would add, 0 to 1. Since v3.
|
|
64
|
+
*
|
|
65
|
+
* Measured in tilt rather than in where the corners landed: sliding the
|
|
66
|
+
* board moves every corner and adds nothing a solve can use, so a signal
|
|
67
|
+
* driven by corner distance would be loudest for the one motion that does
|
|
68
|
+
* not work. One is a view turned as far from everything held as the whole
|
|
69
|
+
* set is required to spread. Zero when nothing usable is in frame.
|
|
70
|
+
*
|
|
71
|
+
* Meant for something continuous -- a tone, a bar, a click rate -- because
|
|
72
|
+
* the operator is holding the board and not reading the screen.
|
|
73
|
+
*/
|
|
74
|
+
novelty(cameraId: string): number;
|
|
75
|
+
/**
|
|
76
|
+
* Which way the board still has to be turned. Since v3.
|
|
77
|
+
*
|
|
78
|
+
* `top-near`, `top-far`, `left-near`, `right-near`, or empty outside a live
|
|
79
|
+
* session. The direction least represented in what has been collected, so
|
|
80
|
+
* that "tilt it more" -- an instruction the operator has to interpret --
|
|
81
|
+
* becomes one they can carry out.
|
|
82
|
+
*/
|
|
83
|
+
tiltDirection(cameraId: string): TiltDirection;
|
|
61
84
|
/** Solves from the accepted samples and releases the camera. */
|
|
62
85
|
solve(cameraId: string): Promise<void>;
|
|
63
86
|
/** Hands the solved profile to Camera Source, which owns the profile contract. */
|
|
@@ -155,6 +178,8 @@ export function createRuntimeCapability(
|
|
|
155
178
|
setAutomatic: (cameraId, enabled) => host.setAutomatic(cameraId, enabled),
|
|
156
179
|
automatic: (cameraId) => host.automatic(cameraId),
|
|
157
180
|
guidance: (cameraId) => host.guidance(cameraId),
|
|
181
|
+
novelty: (cameraId) => host.novelty(cameraId),
|
|
182
|
+
tiltDirection: (cameraId) => host.tiltDirection(cameraId),
|
|
158
183
|
solve: (cameraId) => host.solve(cameraId),
|
|
159
184
|
publish: (cameraId) => host.publish(cameraId),
|
|
160
185
|
cancel: (cameraId) => host.cancel(cameraId),
|
package/src/runtime.ts
CHANGED