@trillboards/edge-sdk 0.2.267 → 0.2.276

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.
Files changed (115) hide show
  1. package/deploy/detector/pyproject.toml +1 -1
  2. package/deploy/detector/tests/test_loader.py +1 -1
  3. package/deploy/detector/tests/test_staff_uniform.py +342 -0
  4. package/deploy/detector/trillboards_detector/_version.py +2 -2
  5. package/deploy/detector/trillboards_detector/loader.py +6 -0
  6. package/deploy/detector/trillboards_detector/registry.py +30 -1
  7. package/deploy/detector/trillboards_detector/server.py +43 -0
  8. package/deploy/detector/trillboards_detector/staff_uniform.py +190 -0
  9. package/deploy/detector/trillboards_detector/tasks.py +9 -1
  10. package/deploy/windows/build-windows.ps1 +3 -0
  11. package/deploy/windows/ci/test-published-install.ps1 +1 -1
  12. package/deploy/windows/e2e/test-recorder-family.ps1 +1 -1
  13. package/deploy/windows/process-priority.ps1 +229 -0
  14. package/dist/ActorPerception.d.ts.map +1 -1
  15. package/dist/ActorPerception.js +3 -1
  16. package/dist/ActorPerception.js.map +1 -1
  17. package/dist/AlertClips.d.ts +120 -0
  18. package/dist/AlertClips.d.ts.map +1 -1
  19. package/dist/AlertClips.js +296 -17
  20. package/dist/AlertClips.js.map +1 -1
  21. package/dist/AudienceAnalyzeClient.d.ts +34 -0
  22. package/dist/AudienceAnalyzeClient.d.ts.map +1 -1
  23. package/dist/AudienceAnalyzeClient.js +89 -15
  24. package/dist/AudienceAnalyzeClient.js.map +1 -1
  25. package/dist/CctvLiveViewCoordinator.d.ts +23 -2
  26. package/dist/CctvLiveViewCoordinator.d.ts.map +1 -1
  27. package/dist/CctvLiveViewCoordinator.js +50 -0
  28. package/dist/CctvLiveViewCoordinator.js.map +1 -1
  29. package/dist/ConnectorStatusClient.d.ts +8 -0
  30. package/dist/ConnectorStatusClient.d.ts.map +1 -1
  31. package/dist/ConnectorStatusClient.js +3 -0
  32. package/dist/ConnectorStatusClient.js.map +1 -1
  33. package/dist/DetectorFields.d.ts +114 -7
  34. package/dist/DetectorFields.d.ts.map +1 -1
  35. package/dist/DetectorFields.js +168 -43
  36. package/dist/DetectorFields.js.map +1 -1
  37. package/dist/EdgeAgent.js +1 -1
  38. package/dist/FloorObjects.d.ts +131 -8
  39. package/dist/FloorObjects.d.ts.map +1 -1
  40. package/dist/FloorObjects.js +396 -24
  41. package/dist/FloorObjects.js.map +1 -1
  42. package/dist/LocalDetectorClient.d.ts +21 -0
  43. package/dist/LocalDetectorClient.d.ts.map +1 -1
  44. package/dist/LocalDetectorClient.js +43 -0
  45. package/dist/LocalDetectorClient.js.map +1 -1
  46. package/dist/NativeReadiness.d.ts.map +1 -1
  47. package/dist/NativeReadiness.js +8 -3
  48. package/dist/NativeReadiness.js.map +1 -1
  49. package/dist/QueueDwell.d.ts +87 -0
  50. package/dist/QueueDwell.d.ts.map +1 -0
  51. package/dist/QueueDwell.js +167 -0
  52. package/dist/QueueDwell.js.map +1 -0
  53. package/dist/ScopedVlmReview.d.ts +21 -2
  54. package/dist/ScopedVlmReview.d.ts.map +1 -1
  55. package/dist/ScopedVlmReview.js +68 -10
  56. package/dist/ScopedVlmReview.js.map +1 -1
  57. package/dist/SensingProfileClient.d.ts +7 -0
  58. package/dist/SensingProfileClient.d.ts.map +1 -1
  59. package/dist/SensingProfileClient.js +1 -0
  60. package/dist/SensingProfileClient.js.map +1 -1
  61. package/dist/VideoSegmentUploader.d.ts +6 -0
  62. package/dist/VideoSegmentUploader.d.ts.map +1 -1
  63. package/dist/VideoSegmentUploader.js +31 -4
  64. package/dist/VideoSegmentUploader.js.map +1 -1
  65. package/dist/config.d.ts +8 -0
  66. package/dist/config.d.ts.map +1 -1
  67. package/dist/config.js.map +1 -1
  68. package/dist/connectorUpdate.d.ts +6 -0
  69. package/dist/connectorUpdate.d.ts.map +1 -1
  70. package/dist/connectorUpdate.js +8 -1
  71. package/dist/connectorUpdate.js.map +1 -1
  72. package/dist/diagnose.d.ts +1 -1
  73. package/dist/diagnose.js +1 -1
  74. package/dist/enterpriseNetwork.d.ts +9 -0
  75. package/dist/enterpriseNetwork.d.ts.map +1 -1
  76. package/dist/enterpriseNetwork.js +14 -0
  77. package/dist/enterpriseNetwork.js.map +1 -1
  78. package/dist/index.d.ts +1 -1
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/localSensing.d.ts +29 -1
  81. package/dist/localSensing.d.ts.map +1 -1
  82. package/dist/localSensing.js +64 -6
  83. package/dist/localSensing.js.map +1 -1
  84. package/dist/mainThreadStall.d.ts +11 -0
  85. package/dist/mainThreadStall.d.ts.map +1 -1
  86. package/dist/mainThreadStall.js +35 -0
  87. package/dist/mainThreadStall.js.map +1 -1
  88. package/dist/pipelineSwitches.d.ts +61 -2
  89. package/dist/pipelineSwitches.d.ts.map +1 -1
  90. package/dist/pipelineSwitches.js +93 -15
  91. package/dist/pipelineSwitches.js.map +1 -1
  92. package/dist/processPriority.d.ts +75 -0
  93. package/dist/processPriority.d.ts.map +1 -0
  94. package/dist/processPriority.js +380 -0
  95. package/dist/processPriority.js.map +1 -0
  96. package/dist/sensingRunMode.d.ts.map +1 -1
  97. package/dist/sensingRunMode.js +22 -3
  98. package/dist/sensingRunMode.js.map +1 -1
  99. package/dist/vehicleEndWarmup.d.ts +60 -0
  100. package/dist/vehicleEndWarmup.d.ts.map +1 -0
  101. package/dist/vehicleEndWarmup.js +209 -0
  102. package/dist/vehicleEndWarmup.js.map +1 -0
  103. package/dist/windowsLiveView.d.ts +3 -1
  104. package/dist/windowsLiveView.d.ts.map +1 -1
  105. package/dist/windowsLiveView.js +2 -0
  106. package/dist/windowsLiveView.js.map +1 -1
  107. package/package.json +4 -4
  108. package/retained/RetainedCaptureClient.cjs +30 -4
  109. package/retained/__tests__/archive-lifecycle.test.cjs +44 -0
  110. package/retained/__tests__/held-frames.test.cjs +94 -0
  111. package/retained/__tests__/paired-theft-manager.test.cjs +24 -0
  112. package/retained/__tests__/queue-dwell.test.cjs +238 -0
  113. package/retained/__tests__/support/theft-builder.cjs +3 -1
  114. package/retained/held-frames.cjs +39 -0
  115. package/retained/manager.cjs +15 -0
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FLOOR_OBJECT_LEFT_V1 = exports.FLOOR_OBJECT_LEFT_METHOD = void 0;
3
+ exports.FLOOR_OBJECT_LEFT_V2 = exports.FLOOR_OBJECT_LEFT_V1 = exports.FLOOR_OBJECT_LEFT_V2_METHOD = exports.FLOOR_OBJECT_LEFT_METHOD = void 0;
4
4
  exports.decodeFloorGrey = decodeFloorGrey;
5
5
  exports.readFloorObjectMemory = readFloorObjectMemory;
6
6
  exports.floorPeopleHold = floorPeopleHold;
@@ -79,6 +79,7 @@ const SceneMarks_1 = require("./SceneMarks");
79
79
  * (UniformSceneStore keeps it on disk), and a malformed one costs relearning, never a refusal.
80
80
  */
81
81
  exports.FLOOR_OBJECT_LEFT_METHOD = 'floor_object_left_v1';
82
+ exports.FLOOR_OBJECT_LEFT_V2_METHOD = 'floor_object_left_v2';
82
83
  /**
83
84
  * The pinned numbers (every value but `field`): the parser refuses any other. Measured on the Texas aisle cameras'
84
85
  * recorded days (docs/runbooks/cctv-detector-tier.md section 5l).
@@ -96,6 +97,88 @@ exports.FLOOR_OBJECT_LEFT_V1 = Object.freeze({
96
97
  settleMove: 0.08, minFreeShare: 0.5 }),
97
98
  people: Object.freeze({ reuseDiff: 5, refreshMs: 60000 }),
98
99
  });
100
+ /**
101
+ * floor_object_left_v2: v1's numbers, plus the frames the camera held between two looks (`trail`) and the release of
102
+ * a decided object carried off (`release`). Measured on the same recorded days at the looks' own pace (30 s and the
103
+ * shared rotation) over five look phases (docs/runbooks/cctv-detector-tier.md section 5l). A blank look (every pixel
104
+ * within BLANK_RANGE grey levels: the one-grey frame a camera's stream gives on a dropout) or a damaged one (its bottom
105
+ * rows lost by the stream and made up smooth, damagedTail) is no look at all, and such a held frame is left out of the
106
+ * trail. An object, or a cell's start, missed on one look is kept through that look at any pace (object.missGraceMs
107
+ * or the gap since the last look and a second, whichever is longer), and an object whose cells pass for the floor but
108
+ * look more like it than like the floor it covers is kept for as long as they do (decided only on a look that finds it).
109
+ * A ghost learned keeps the floor it replaced for reference.ownMs, as a change nobody brought does.
110
+ */
111
+ exports.FLOOR_OBJECT_LEFT_V2 = Object.freeze({
112
+ ...exports.FLOOR_OBJECT_LEFT_V1,
113
+ trail: Object.freeze({ pitchMs: 4000, maxFrames: 16, moveDiff: 12, maxShare: 0.3, minMoves: 2 }),
114
+ release: Object.freeze({ radius: 2, wideRadius: 4, minFree: 3, maxLeft: 0.25 }),
115
+ });
116
+ /**
117
+ * v2: a look whose every pixel lies within this many grey levels of the others shows nothing. Texas camera 10, Oct 27
118
+ * 04:01 CDT: one look of flat grey 130 between two 14 s apart; v1 judged it a lighting change and learned it, and the
119
+ * wet-floor sign standing at the far end, every cell of it now flat, was taken for carried off.
120
+ */
121
+ const BLANK_RANGE = 4;
122
+ function blankLook(frame) {
123
+ const d = frame.data;
124
+ let lo = d[0], hi = d[0];
125
+ for (let i = 1; i < d.length; i++) {
126
+ const v = d[i];
127
+ if (v < lo)
128
+ lo = v;
129
+ else if (v > hi)
130
+ hi = v;
131
+ if (hi - lo > BLANK_RANGE)
132
+ return false;
133
+ }
134
+ return true;
135
+ }
136
+ /**
137
+ * v2: a look whose bottom rows the stream lost. A lost packet damages a frame from where it fell to the frame's end,
138
+ * and the decoder fills the damage in smooth: bottom rows under DAMAGE_LOW grey levels between neighbouring pixels on
139
+ * average, where the frames the camera held just before had at least 1/DAMAGE_RATIO times that. Texas camera 16, Oct
140
+ * 31 15:04 CDT: about one frame in forty had its bottom rows made up that week; each such look took the foot of the
141
+ * inflatable display standing at the area's edge for carried off, and it alerted again from the next look on, 7 to 9
142
+ * alerts an afternoon. A row smooth in every held frame (a black band, a plain floor) tells nothing and is passed
143
+ * over. A look, or a held frame, is judged only against the DAMAGE_BEFORE frames the camera held just before it, never
144
+ * the whole trail: a look this skips leaves the floor memory's last look where it was, so the next look's trail still
145
+ * begins with that older frame, and a change that stays (a sheet laid across the bottom, the lights) is judged as usual
146
+ * once the frames just before a look show it too.
147
+ */
148
+ const DAMAGE_LOW = 4, DAMAGE_RATIO = 0.4, DAMAGE_BEFORE = 2;
149
+ /** Mean grey step between neighbouring pixels along each of the bottom fifth's rows, the bottom row first. */
150
+ function tailRoughness(frame) {
151
+ const W = frame.width, H = frame.height, d = frame.data, out = new Float32Array(Math.ceil(H / 5));
152
+ for (let r = 0; r < out.length; r++) {
153
+ const b = (H - 1 - r) * W;
154
+ let s = 0;
155
+ for (let x = 1; x < W; x++)
156
+ s += Math.abs(d[b + x] - d[b + x - 1]);
157
+ out[r] = W > 1 ? s / (W - 1) : 0;
158
+ }
159
+ return out;
160
+ }
161
+ /** At least a 48th of the frame's height, from its bottom, smooth where the frames before were not. */
162
+ function damagedTail(now, before, height) {
163
+ if (!before.length)
164
+ return false;
165
+ let run = 0;
166
+ for (let r = 0; r < now.length; r++) {
167
+ let base = 0;
168
+ for (const b of before)
169
+ if (b[r] > base)
170
+ base = b[r];
171
+ if (base < DAMAGE_LOW)
172
+ continue;
173
+ if (now[r] < DAMAGE_LOW && now[r] < DAMAGE_RATIO * base)
174
+ run++;
175
+ else
176
+ break;
177
+ }
178
+ return run >= Math.ceil(height / 48);
179
+ }
180
+ const sameShape = (a, b) => a.width === b.width && a.height === b.height
181
+ && a.data.length === b.data.length;
99
182
  const B64 = (bytes) => Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString('base64');
100
183
  const fromB64 = (s) => {
101
184
  const b = Buffer.from(s, 'base64');
@@ -305,12 +388,13 @@ function floorObjectDueAtMs(memory, method) {
305
388
  return due.length ? Math.min(...due) : null;
306
389
  }
307
390
  /**
308
- * floor_object_left_v1 on one look. `frame` is the look's grey decode at grid.height (decodeFloorGrey), `size` the
309
- * original frame the detections are pixels of. A look not captured after the memory's last one decides from the
391
+ * floor_object_left_v1 or v2 on one look. `frame` is the look's grey decode at grid.height (decodeFloorGrey), `size`
392
+ * the original frame the detections are pixels of. A look not captured after the memory's last one decides from the
310
393
  * memory and teaches nothing.
311
394
  */
312
395
  function decideFloorObjects(input) {
313
396
  const m = input.method, t = input.capturedAtMs, f = input.frame;
397
+ const v2 = m.method === exports.FLOOR_OBJECT_LEFT_V2_METHOD ? m : null;
314
398
  if (!time(t) || t < 0)
315
399
  throw Error('Floor objects need the capture time');
316
400
  if (!(f.width > m.grid.cell && f.height === m.grid.height) || f.data.length !== f.width * f.height) {
@@ -340,7 +424,7 @@ function decideFloorObjects(input) {
340
424
  const decidedBoxes = (objects) => objects.filter(o => o.decidedMs !== null)
341
425
  .map(o => ({ ...cellsBox(o.cells, g), confidence: 1 }));
342
426
  const trace = (memory, extra) => ({
343
- method: 'floor_object_left_v1', imageSha256: input.imageSha256, policySha256: input.policySha256,
427
+ method: m.method, imageSha256: input.imageSha256, policySha256: input.policySha256,
344
428
  cells: g.insideCount, changed: 0, gain: 1, quiet: false, lighting: false, ghosts: 0, marked: 0, unbrought: 0,
345
429
  returned: 0, ...peopleTrace,
346
430
  objects: memory.objects.map(o => ({ box: cellsBox(o.cells, g), firstMs: o.firstMs, stillMs: o.stillMs,
@@ -350,6 +434,14 @@ function decideFloorObjects(input) {
350
434
  if (t <= prior.lastAtMs) {
351
435
  return { value: answer(prior), memory: prior, trace: trace(prior, {}), causes: decidedBoxes(prior.objects) };
352
436
  }
437
+ if (v2 && blankLook(f)) {
438
+ return { value: answer(prior), memory: prior, trace: trace(prior, { blank: true }), causes: decidedBoxes(prior.objects) };
439
+ }
440
+ if (v2 && damagedTail(tailRoughness(f), (input.held ?? []).filter(h => h && h.frame && time(h.atMs) && h.atMs < t
441
+ && sameShape(h.frame, f) && !blankLook(h.frame)).sort((x, y) => x.atMs - y.atMs).slice(-DAMAGE_BEFORE)
442
+ .map(h => tailRoughness(h.frame)), f.height)) {
443
+ return { value: answer(prior), memory: prior, trace: trace(prior, { damaged: true }), causes: decidedBoxes(prior.objects) };
444
+ }
353
445
  const quiet = g.area.every(i => !near[i]);
354
446
  // Whole seconds since a bringer was near each cell, and how each differing cell began (SOMEBODY LEFT IT).
355
447
  const O = m.object;
@@ -362,8 +454,38 @@ function decideFloorObjects(input) {
362
454
  nearAge[k] = b[2 * k] | (b[2 * k + 1] << 8);
363
455
  }
364
456
  const elapsed = prior.lastAtMs >= 0 ? Math.round((t - prior.lastAtMs) / 1000) : 0;
457
+ // v2: missed on one look is kept through that look, at any pace. v1's missGraceMs spans a few looks at a look every
458
+ // 2-4 s and none at a look every 30 s: Texas camera 10's wet-floor sign at the far end (Oct 25 14:53 CDT) showed its
459
+ // two cells on one look and one cell on the next, was dropped and began again at each two-cell look, and was first
460
+ // reported the next day.
461
+ const missGraceMs = v2 && prior.lastAtMs >= 0 ? Math.max(O.missGraceMs, t - prior.lastAtMs + 1000) : O.missGraceMs;
365
462
  for (let k = 0; k < n; k++)
366
463
  nearAge[k] = bringers[g.area[k]] ? 0 : Math.min(65535, nearAge[k] + elapsed);
464
+ // v2: whoever came and went between the two looks (trailVisits) was near their cells, widened like a bringer's box,
465
+ // as of the last held frame they were in. At a 30 s look a shopper who set a bag down and walked on is in no look.
466
+ let heldUsed = 0, visitedCells = 0;
467
+ if (v2 && input.held?.length && prior.lastAtMs >= 0) {
468
+ const trail = trailVisits(input.held, f, t, prior.lastAtMs, g, v2);
469
+ heldUsed = trail.frames;
470
+ const R = m.reference.quietRing;
471
+ for (let i = 0; i < trail.at.length; i++) {
472
+ const at = trail.at[i];
473
+ if (Number.isNaN(at))
474
+ continue;
475
+ if (g.inside[i])
476
+ visitedCells++;
477
+ const age = Math.max(0, Math.round((t - at) / 1000)), r = Math.floor(i / g.cols), c = i % g.cols;
478
+ for (let dr = -R; dr <= R; dr++)
479
+ for (let dc = -R; dc <= R; dc++) {
480
+ const rr = r + dr, cc = c + dc;
481
+ if (rr < 0 || rr >= g.rows || cc < 0 || cc >= g.cols)
482
+ continue;
483
+ const k = g.slot[rr * g.cols + cc];
484
+ if (k >= 0 && age < nearAge[k])
485
+ nearAge[k] = age;
486
+ }
487
+ }
488
+ }
367
489
  const nearB64 = () => {
368
490
  const out = new Uint8Array(n * 2);
369
491
  for (let k = 0; k < n; k++) {
@@ -513,7 +635,7 @@ function decideFloorObjects(input) {
513
635
  }
514
636
  else {
515
637
  age = Math.min(63, age + elapsed);
516
- if (age * 1000 >= O.missGraceMs)
638
+ if (age * 1000 >= missGraceMs)
517
639
  state = 0;
518
640
  }
519
641
  onset[k] = state | (age << 2);
@@ -530,6 +652,20 @@ function decideFloorObjects(input) {
530
652
  cells.forEach((i, j) => out.set(px.subarray(g.slot[i] * 64, g.slot[i] * 64 + 64), j * 64));
531
653
  return B64(out);
532
654
  };
655
+ // v2: the snapshot of an object whose cells changed, row by row: a cell it kept keeps its pixels from when it
656
+ // settled, a cell it took on is taken as it looks now. v1 kept the old rows under the new cell list, so a cell's
657
+ // still test read another cell's pixels once the object gained or lost an edge cell.
658
+ const carrySnap = (o, cells) => {
659
+ const old = fromB64(o.snap), at = new Map(o.cells.map((i, j) => [i, j]));
660
+ if (old.byteLength !== o.cells.length * 64)
661
+ return snapOf(cells);
662
+ const out = new Uint8Array(cells.length * 64);
663
+ cells.forEach((i, j) => {
664
+ const was = at.get(i);
665
+ out.set(was === undefined ? px.subarray(g.slot[i] * 64, g.slot[i] * 64 + 64) : old.subarray(was * 64, was * 64 + 64), j * 64);
666
+ });
667
+ return B64(out);
668
+ };
533
669
  // Cells whose floor this look learned in bulk (a relearn, a quiet look): the light the floor is learned in.
534
670
  const learned = new Uint8Array(g.cols * g.rows);
535
671
  const absorb = (cells) => {
@@ -540,6 +676,14 @@ function decideFloorObjects(input) {
540
676
  seen[k] = Math.max(seen[k], 1);
541
677
  }
542
678
  };
679
+ // Before a learned change is absorbed: the floor it replaces, kept for ownMs (the oldest, where a cell learned twice).
680
+ const keepReplaced = (cells) => {
681
+ for (const i of cells) {
682
+ const k = g.slot[i];
683
+ if (!own.has(i))
684
+ own.set(i, [t, Uint8Array.from({ length: 64 }, (_, j) => Math.min(255, Math.round(ref[k * 64 + j] / 16)))]);
685
+ }
686
+ };
543
687
  // The whole free floor at once, at this look's brightness (the gain starts again from 1). The floors that learned
544
688
  // changes replaced are of the old brightness: forgotten.
545
689
  const relearn = (cells) => { absorb(cells); settled(cells); own.clear(); for (const i of cells)
@@ -635,8 +779,31 @@ function decideFloorObjects(input) {
635
779
  });
636
780
  pairs.sort((a, b) => b.v - a.v || a.o - b.o || a.p - b.p);
637
781
  const usedO = new Set(stays.keys()), usedP = new Set();
638
- for (const [oi, cells] of stays)
639
- objects.push({ ...prior.objects[oi], cells, seenMs: t });
782
+ for (const [oi, cells] of stays) {
783
+ objects.push({ ...prior.objects[oi], cells, seenMs: t, ...(v2 ? { snap: carrySnap(prior.objects[oi], cells) } : {}) });
784
+ }
785
+ /** v2: every cell of an object inside the area with no person on it looks more like the object's snapshot than like
786
+ * the reference floor (mean absolute grey difference, the reference at this look's gain). */
787
+ const standing = (o) => {
788
+ const snap = fromB64(o.snap);
789
+ if (snap.byteLength !== o.cells.length * 64)
790
+ return false;
791
+ let judged = 0;
792
+ for (let j = 0; j < o.cells.length; j++) {
793
+ const i = o.cells[j], k = g.slot[i];
794
+ if (!g.inside[i] || person[i])
795
+ continue;
796
+ let dSnap = 0, dRef = 0;
797
+ for (let x = 0; x < 64; x++) {
798
+ dSnap += Math.abs(px[k * 64 + x] - snap[j * 64 + x]);
799
+ dRef += Math.abs(px[k * 64 + x] - gain * ref[k * 64 + x] / 16);
800
+ }
801
+ if (dSnap >= dRef)
802
+ return false;
803
+ judged++;
804
+ }
805
+ return judged > 0;
806
+ };
640
807
  const touched = (cells) => cells.some(i => {
641
808
  const r = Math.floor(i / g.cols), c = i % g.cols;
642
809
  for (let dr = -1; dr <= 1; dr++)
@@ -668,21 +835,33 @@ function decideFloorObjects(input) {
668
835
  const union = new Set([...cells, ...o.cells]).size;
669
836
  const moved = count === 0 || diff / count > O.stableDiff || (count / 64) / union < 0.5 || touched(cells);
670
837
  objects.push({ id: o.id, cells, firstMs: o.firstMs, stillMs: moved ? t : o.stillMs, seenMs: t,
671
- decidedMs: o.decidedMs, snap: moved ? snapOf(cells) : o.snap, brought: broughtOf(cells) });
838
+ decidedMs: o.decidedMs, snap: moved ? snapOf(cells) : v2 ? carrySnap(o, cells) : o.snap, brought: broughtOf(cells) });
672
839
  }
673
840
  prior.objects.forEach((o, oi) => {
674
841
  if (usedO.has(oi))
675
842
  return;
676
- // Hidden behind a person: still there, but touched. Missed on one look: kept, untouched, for missGraceMs. An object
677
- // seen standing a dwell past its decision is kept for a dwell, so its alert does not end and come back when a small
678
- // object's cells pass for the floor on a few looks (Texas camera 10, Oct 26 15:02 CDT: a wet-floor sign at the far
679
- // end, 16 s, nobody near). One gone within a dwell of its decision keeps missGraceMs: on that camera over 13 days,
680
- // five such were an employee standing at the far end and passing changes with nothing on the floor, and a dwell's
681
- // grace would have alerted on each.
843
+ // Hidden behind a person: still there, but touched. Missed on one look: kept, untouched, for missGraceMs (v2: at
844
+ // least through that look, at any pace). An object seen standing a dwell past its decision is kept for a dwell, so
845
+ // its alert does not end and come back when a small object's cells pass for the floor on a few looks (Texas camera
846
+ // 10, Oct 26 15:02 CDT: a wet-floor sign at the far end, 16 s, nobody near). One gone within a dwell of its
847
+ // decision keeps missGraceMs: on that camera over 13 days, five such were an employee standing at the far end and
848
+ // passing changes with nothing on the floor, and a dwell's grace would have alerted on each.
682
849
  const hidden = o.cells.filter(i => person[i]).length >= 0.5 * o.cells.length;
683
- const grace = o.decidedMs !== null && o.seenMs - o.decidedMs >= O.dwellMs ? O.dwellMs : O.missGraceMs;
850
+ const grace = o.decidedMs !== null && o.seenMs - o.decidedMs >= O.dwellMs ? Math.max(O.dwellMs, missGraceMs) : missGraceMs;
684
851
  if (hidden)
685
852
  objects.push({ ...o, cells: [...o.cells], stillMs: t, seenMs: t });
853
+ // v2: a decided object whose cells pass for the floor on this look but look more like the object as it settled
854
+ // than like the floor it covers is still standing there. A wet-floor sign at the far end of Texas camera 10's
855
+ // aisle (Oct 25) passes for the floor on some looks; at a look every 30 s two such in a row outlasted the grace,
856
+ // the sign was dropped, learned as floor, and its ghost alerted three days later beside a patch of light.
857
+ else if (v2 && o.decidedMs !== null && standing(o))
858
+ objects.push({ ...o, cells: [...o.cells], seenMs: t });
859
+ // v2: so is one not yet decided, kept but not seen: it is decided only on a look that finds it. The wet-floor sign
860
+ // at the far end of camera 10's aisle (Oct 25 14:54 CDT) showed its two cells on two looks and one on the next two,
861
+ // over and over; at a look every 30 s the second miss outlasted the grace, it began again at each two-cell look,
862
+ // was never found still for a dwell, and was first reported the next day.
863
+ else if (v2 && standing(o))
864
+ objects.push({ ...o, cells: [...o.cells] });
686
865
  else if (t - o.seenMs <= grace)
687
866
  objects.push({ ...o, cells: [...o.cells] });
688
867
  });
@@ -739,7 +918,18 @@ function decideFloorObjects(input) {
739
918
  if (o.seenMs !== t || t - o.stillMs < G.afterMs)
740
919
  continue;
741
920
  if (o.decidedMs !== null) {
742
- if (o.cells.some(i => person[i]) || !isGhost(o.cells, px, ref, gain, g, person, G))
921
+ if (o.cells.some(i => person[i]))
922
+ continue;
923
+ // v2: carried off (carriedOff), all of it the floor. Judged before v1's ghost test, which can find the whole
924
+ // object a ghost while no cell of it is one by itself, and then keeps all of it (Texas camera 10, Oct 31: the
925
+ // pallets left at 09:15 CDT and the alert held to the next week).
926
+ if (v2 && carriedOff(o, objects, px, mean, g, person, changed, G, v2, O.stableDiff)) {
927
+ absorb(o.cells);
928
+ objects.splice(k, 1);
929
+ ghosts++;
930
+ continue;
931
+ }
932
+ if (!isGhost(o.cells, px, ref, gain, g, person, G))
743
933
  continue;
744
934
  // Cell by cell: what is itself a ghost is the floor; what is left goes on if it is still an object (a basket
745
935
  // set down among the cells a step ladder had stood in, Texas camera 8, Oct 28). Not an object any more: all
@@ -750,7 +940,7 @@ function decideFloorObjects(input) {
750
940
  if (!gone.size)
751
941
  continue;
752
942
  absorb([...gone]);
753
- objects[k] = { ...o, cells: left };
943
+ objects[k] = { ...o, cells: left, ...(v2 ? { snap: carrySnap(o, left) } : {}) };
754
944
  }
755
945
  else {
756
946
  absorb(o.cells);
@@ -769,17 +959,21 @@ function decideFloorObjects(input) {
769
959
  }
770
960
  else if (!o.brought) {
771
961
  // The floor it replaces stays able to come back (the oldest, where a cell learned twice).
772
- for (const i of o.cells) {
773
- const k2 = g.slot[i];
774
- if (!own.has(i))
775
- own.set(i, [t, Uint8Array.from({ length: 64 }, (_, j) => Math.min(255, Math.round(ref[k2 * 64 + j] / 16)))]);
776
- }
962
+ keepReplaced(o.cells);
777
963
  absorb(o.cells);
778
964
  settled(o.cells);
779
965
  objects.splice(k, 1);
780
966
  unbrought++;
781
967
  }
782
- else if (isGhost(o.cells, px, ref, gain, g, person, G)) {
968
+ else if (isGhost(o.cells, px, ref, gain, g, person, G)
969
+ || v2 && ghostNear(o, objects, px, mean, ref, gain, g, person, changed, G, v2)) {
970
+ // v2: so does the floor a ghost replaces. At the far end of Texas camera 10's aisle the floor brightens by 12-14
971
+ // grey levels and goes back, in steps (Oct 29, twice between 12:52 and 12:57 CDT). With shoppers near it the
972
+ // patch passed for a ghost and was learned without the floor it covered; when the light went, that floor came
973
+ // back with shoppers near, was taken for something they brought, alerted, and held the alert for 37 hours.
974
+ // Learned with nobody near, the same patch had gone back at once four minutes before.
975
+ if (v2)
976
+ keepReplaced(o.cells);
783
977
  absorb(o.cells);
784
978
  objects.splice(k, 1);
785
979
  ghosts++;
@@ -888,7 +1082,185 @@ function decideFloorObjects(input) {
888
1082
  own: [...own].slice(-4096).map(([i, [at, prev]]) => [i, at, B64(prev)]) };
889
1083
  return { value: answer(memory), memory, causes: decidedBoxes(objects),
890
1084
  trace: trace(memory, { changed: differ, gain: Math.round(gain * 1000) / 1000, quiet, lighting: lighting || relit, ghosts, marked,
891
- unbrought, returned }) };
1085
+ unbrought, returned, ...(v2 ? { held: heldUsed, visited: visitedCells } : {}) }) };
1086
+ }
1087
+ /**
1088
+ * v2: who came and went between two looks. The frames the camera held since the last look (`held`, the last look's own
1089
+ * frame first) and this look, compared in sequence cell by cell (each cell's mean absolute grey difference): a cell
1090
+ * moved between two frames when that exceeds trail.moveDiff. A pair in which more than trail.maxShare of the area
1091
+ * moved is the lights or the camera, never a person, and counts for nothing. A cell that moved trail.minMoves times
1092
+ * or more had something come and go: a person walking past, a hand setting a box down. A cell that moved once only
1093
+ * changed: a bank of lights over a stretch of the aisle, or the box that was left. Per grid cell, the time of the last
1094
+ * frame the visitor was in (NaN: none), and how many held frames were compared.
1095
+ */
1096
+ function trailVisits(held, frame, t, sinceMs, g, m) {
1097
+ const T = m.trail, at = new Float64Array(g.cols * g.rows).fill(NaN);
1098
+ const usable = [];
1099
+ for (const h of held) {
1100
+ if (!h || !h.frame || !time(h.atMs) || h.atMs < sinceMs || h.atMs >= t || !sameShape(h.frame, frame)
1101
+ || blankLook(h.frame))
1102
+ continue;
1103
+ if (usable.length && h.atMs <= usable[usable.length - 1].atMs)
1104
+ continue;
1105
+ usable.push(h);
1106
+ }
1107
+ // A held frame the stream damaged (damagedTail, against the DAMAGE_BEFORE held just before it) is left out too.
1108
+ const tails = usable.map(h => tailRoughness(h.frame));
1109
+ const kept = usable.filter((_, j) => !damagedTail(tails[j], tails.slice(Math.max(0, j - DAMAGE_BEFORE), j), frame.height));
1110
+ const seq = [...kept.slice(-T.maxFrames), { atMs: t, frame }];
1111
+ if (seq.length < 1 + T.minMoves)
1112
+ return { at, frames: seq.length - 1 };
1113
+ const moves = new Uint8Array(g.cols * g.rows), last = new Int32Array(g.cols * g.rows).fill(-1);
1114
+ const moved = new Uint8Array(g.cols * g.rows), cell = g.cell, W = frame.width;
1115
+ for (let j = 1; j < seq.length; j++) {
1116
+ const a = seq[j - 1].frame.data, b = seq[j].frame.data;
1117
+ let inside = 0;
1118
+ for (let r = 0; r < g.rows; r++)
1119
+ for (let c = 0; c < g.cols; c++) {
1120
+ let d = 0;
1121
+ for (let y = 0; y < cell; y++) {
1122
+ const row = (r * cell + y) * W + c * cell;
1123
+ for (let x = 0; x < cell; x++)
1124
+ d += Math.abs(a[row + x] - b[row + x]);
1125
+ }
1126
+ const i = r * g.cols + c;
1127
+ moved[i] = d / (cell * cell) > T.moveDiff ? 1 : 0;
1128
+ if (moved[i] && g.inside[i])
1129
+ inside++;
1130
+ }
1131
+ if (inside > T.maxShare * g.insideCount)
1132
+ continue;
1133
+ for (let i = 0; i < moved.length; i++)
1134
+ if (moved[i]) {
1135
+ moves[i] = Math.min(255, moves[i] + 1);
1136
+ last[i] = j;
1137
+ }
1138
+ }
1139
+ for (let i = 0; i < moves.length; i++)
1140
+ if (moves[i] >= T.minMoves)
1141
+ at[i] = seq[last[i] - 1].atMs;
1142
+ return { at, frames: seq.length - 1 };
1143
+ }
1144
+ /** One cell's 64 pixels at `offset`: their mean, and their edge energy (cellStructure's eNow). */
1145
+ function cellLook(bytes, offset) {
1146
+ let sum = 0, edge = 0;
1147
+ for (let y = 0; y < 8; y++)
1148
+ for (let x = 0; x < 8; x++) {
1149
+ const j = offset + y * 8 + x;
1150
+ if (x < 7)
1151
+ edge += Math.abs(bytes[j + 1] - bytes[j]);
1152
+ if (y < 7)
1153
+ edge += Math.abs(bytes[j + 8] - bytes[j]);
1154
+ sum += bytes[j];
1155
+ }
1156
+ return { mean: sum / 64, edge };
1157
+ }
1158
+ /**
1159
+ * The free floor near cell i: within `radius` cells, or (radius null) anywhere in its row and the rows either side, the
1160
+ * aisle at the same distance from the camera. Its cells' darkest and brightest mean and most edge energy.
1161
+ */
1162
+ function floorNear(i, radius, free, g, px, mean) {
1163
+ const r = Math.floor(i / g.cols), c = i % g.cols, across = radius ?? g.cols, down = radius ?? 1;
1164
+ let lo = Infinity, hi = -Infinity, edge = 0, count = 0;
1165
+ for (let dr = -down; dr <= down; dr++)
1166
+ for (let dc = -across; dc <= across; dc++) {
1167
+ const rr = r + dr, cc = c + dc, j = rr * g.cols + cc;
1168
+ if (rr < 0 || rr >= g.rows || cc < 0 || cc >= g.cols || !free(j))
1169
+ continue;
1170
+ const k = g.slot[j];
1171
+ lo = Math.min(lo, mean[k]);
1172
+ hi = Math.max(hi, mean[k]);
1173
+ edge = Math.max(edge, cellLook(px, k * 64).edge);
1174
+ count++;
1175
+ }
1176
+ return { lo, hi, edge, count };
1177
+ }
1178
+ /**
1179
+ * v2: a decided object carried off, where v1's ghost test cannot tell. v1 compares the whole object with the mean of
1180
+ * the floor touching it, and Texas camera 10's aisle is brighter down its middle than at its sides: the pallets and bins
1181
+ * set down where a cart had stood (Oct 30-31) held the alert for days after they left, the bare floor still unlike the
1182
+ * reference (the cart) and unlike the floor beside it. Judged against what the object looked like when it settled (its
1183
+ * snapshot), cell by cell inside the drawn area (its cells in the ring around the area are a shelf's, and go with it):
1184
+ * - a cell that changed since by more than object.stableDiff is the floor again when the object's structure left it
1185
+ * (the snapshot held more edge energy than the look, by ghost.edgeRatio) or it looks like the free floor near it;
1186
+ * - a cell that did not change and looks like that floor is the floor a see-through object (a rolling ladder, a
1187
+ * cart) showed through its frame;
1188
+ * - any other cell still holds something. At most release.maxLeft of the cells may: the base of a shelf at the area's
1189
+ * edge that the object took in stays as it was when the pallet beside it goes (Texas camera 10, Oct 31: one such
1190
+ * cell held a pallet carried off at 09:10 CDT for six days). A frame still standing holds the object.
1191
+ * The free floor near a cell: cells inside the area, held by no object, no person on them, matching the reference,
1192
+ * within release.radius cells, else release.wideRadius when fewer than release.minFree are free there, else the same
1193
+ * rows of the area (the aisle at that distance). Looking like it: brightness within its darkest and brightest cells,
1194
+ * give or take ghost.floorMeanAbs (or floorMeanRel), and no more edge energy than its most textured cell times
1195
+ * ghost.edgeRatio. An object some of whose cells did not look like that floor when it settled goes once those all
1196
+ * changed; one that looked like the floor even then, once half of it changed.
1197
+ */
1198
+ function carriedOff(o, objects, px, mean, g, person, changed, G, m, stableDiff) {
1199
+ const snap = fromB64(o.snap);
1200
+ if (snap.byteLength !== o.cells.length * 64)
1201
+ return false;
1202
+ const mine = new Set(o.cells), held = new Set(objects.filter(x => x !== o).flatMap(x => x.cells)), R = m.release;
1203
+ const free = (j) => g.slot[j] >= 0 && g.inside[j] === 1 && !mine.has(j) && !held.has(j) && !person[j] && !changed[j];
1204
+ const floorLike = (look, floor) => {
1205
+ const tol = Math.max(G.floorMeanAbs, G.floorMeanRel * look.mean);
1206
+ return floor.count >= R.minFree && look.mean >= floor.lo - tol && look.mean <= floor.hi + tol
1207
+ && look.edge <= floor.edge * G.edgeRatio;
1208
+ };
1209
+ let rough = 0, gone = 0, left = 0, inside = 0;
1210
+ for (let j = 0; j < o.cells.length; j++) {
1211
+ const i = o.cells[j], k = g.slot[i];
1212
+ if (!g.inside[i])
1213
+ continue;
1214
+ inside++;
1215
+ let floor = floorNear(i, R.radius, free, g, px, mean);
1216
+ if (floor.count < R.minFree)
1217
+ floor = floorNear(i, R.wideRadius, free, g, px, mean);
1218
+ if (floor.count < R.minFree)
1219
+ floor = floorNear(i, null, free, g, px, mean);
1220
+ const now = cellLook(px, k * 64), then = cellLook(snap, j * 64), like = floorLike(now, floor);
1221
+ let d = 0;
1222
+ for (let x = 0; x < 64; x++)
1223
+ d += Math.abs(px[k * 64 + x] - snap[j * 64 + x]);
1224
+ if (d / 64 > stableDiff && (like || then.edge > G.edgeRatio * now.edge)) {
1225
+ gone++;
1226
+ if (!floorLike(then, floor))
1227
+ rough++;
1228
+ }
1229
+ else if (!like)
1230
+ left++;
1231
+ }
1232
+ return inside > 0 && left <= R.maxLeft * inside && (rough > 0 || 2 * gone >= inside);
1233
+ }
1234
+ /**
1235
+ * v2: an undecided object that is a ghost, judged cell by cell inside the area against the free floor near each cell
1236
+ * (carriedOff's floor), where v1's ghost test compares the whole object with the mean of every cell touching it: at the
1237
+ * far end of Texas camera 10's aisle those are the bright wall base and an end cap, and a wet-floor sign's ghost
1238
+ * (Oct 27) never matched them. Each inside cell looks like the free floor near it, and at least one held more structure
1239
+ * in the reference than it does now (ghost.edgeRatio): what stood there left. No person on any of its cells.
1240
+ */
1241
+ function ghostNear(o, objects, px, mean, ref, gain, g, person, changed, G, m) {
1242
+ if (o.cells.some(i => person[i]))
1243
+ return false;
1244
+ const mine = new Set(o.cells), held = new Set(objects.filter(x => x !== o).flatMap(x => x.cells)), R = m.release;
1245
+ const free = (j) => g.slot[j] >= 0 && g.inside[j] === 1 && !mine.has(j) && !held.has(j) && !person[j] && !changed[j];
1246
+ let ghost = 0;
1247
+ for (const i of o.cells) {
1248
+ if (!g.inside[i])
1249
+ continue;
1250
+ const k = g.slot[i];
1251
+ let floor = floorNear(i, R.radius, free, g, px, mean);
1252
+ if (floor.count < R.minFree)
1253
+ floor = floorNear(i, R.wideRadius, free, g, px, mean);
1254
+ if (floor.count < R.minFree)
1255
+ floor = floorNear(i, null, free, g, px, mean);
1256
+ const now = cellLook(px, k * 64), tol = Math.max(G.floorMeanAbs, G.floorMeanRel * now.mean);
1257
+ if (floor.count < R.minFree || now.mean < floor.lo - tol || now.mean > floor.hi + tol || now.edge > floor.edge * G.edgeRatio) {
1258
+ return false;
1259
+ }
1260
+ if (cellStructure(k, px, ref, gain).eRef > G.edgeRatio * now.edge)
1261
+ ghost++;
1262
+ }
1263
+ return ghost > 0;
892
1264
  }
893
1265
  /**
894
1266
  * A ghost: the reference holds more structure in these cells than the look does (the edges were the object's), and