@trillboards/edge-sdk 0.2.191 → 0.2.193
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/deploy/detector/pyproject.toml +1 -1
- package/deploy/detector/tests/test_detection_colors_wire.py +134 -0
- package/deploy/detector/trillboards_detector/_version.py +2 -2
- package/deploy/detector/trillboards_detector/colors.py +85 -0
- package/deploy/detector/trillboards_detector/server.py +27 -0
- package/dist/DetectionColors.d.ts +44 -0
- package/dist/DetectionColors.d.ts.map +1 -0
- package/dist/DetectionColors.js +51 -0
- package/dist/DetectionColors.js.map +1 -0
- package/dist/DetectorFields.d.ts +213 -0
- package/dist/DetectorFields.d.ts.map +1 -0
- package/dist/DetectorFields.js +205 -0
- package/dist/DetectorFields.js.map +1 -0
- package/dist/EdgeAgent.js +1 -1
- package/dist/LocalDetectorClient.d.ts +4 -1
- package/dist/LocalDetectorClient.d.ts.map +1 -1
- package/dist/LocalDetectorClient.js +24 -1
- package/dist/LocalDetectorClient.js.map +1 -1
- package/dist/RetainedFieldContract.d.ts +1 -1
- package/dist/RetainedFieldContract.d.ts.map +1 -1
- package/dist/RetainedFieldContract.js +8 -1
- package/dist/RetainedFieldContract.js.map +1 -1
- package/dist/ReviewModelUse.d.ts.map +1 -1
- package/dist/ReviewModelUse.js +4 -0
- package/dist/ReviewModelUse.js.map +1 -1
- package/dist/ScopedVlmReview.d.ts +41 -0
- package/dist/ScopedVlmReview.d.ts.map +1 -1
- package/dist/ScopedVlmReview.js +160 -8
- package/dist/ScopedVlmReview.js.map +1 -1
- package/dist/SensingProfileClient.d.ts +3 -0
- package/dist/SensingProfileClient.d.ts.map +1 -1
- package/dist/SensingProfileClient.js +2 -0
- package/dist/SensingProfileClient.js.map +1 -1
- package/dist/diagnose.d.ts +1 -1
- package/dist/diagnose.js +1 -1
- package/dist/localSensing.d.ts +8 -0
- package/dist/localSensing.d.ts.map +1 -1
- package/dist/localSensing.js +86 -4
- package/dist/localSensing.js.map +1 -1
- package/package.json +1 -1
- package/retained/ProfileAuthorityClient.cjs +2 -1
|
@@ -10,7 +10,7 @@ name = "trillboards-detector"
|
|
|
10
10
|
# constant, a `labels.py`-only change survives `uv tool install` AND
|
|
11
11
|
# `uv tool install --force`; move the version and a bare `uv tool install`
|
|
12
12
|
# reinstalls. See `stamp_version.py`.
|
|
13
|
-
version = "0.2.0+src.
|
|
13
|
+
version = "0.2.0+src.abd83bba2f51"
|
|
14
14
|
description = "On-device object-detector service for the Trillboards BYO-CCTV connector (loopback HTTP, ONNX Runtime)."
|
|
15
15
|
requires-python = ">=3.10"
|
|
16
16
|
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"""Real HTTP. Uniform-colour share of each confident person box, on the original frame."""
|
|
2
|
+
import importlib.util
|
|
3
|
+
import unittest
|
|
4
|
+
_missing = [name for name in ["PIL", "numpy"] if importlib.util.find_spec(name) is None]
|
|
5
|
+
if _missing:
|
|
6
|
+
raise unittest.SkipTest("detector[cpu] dependencies absent: " + ", ".join(_missing))
|
|
7
|
+
import base64
|
|
8
|
+
import hashlib
|
|
9
|
+
import io
|
|
10
|
+
import json
|
|
11
|
+
import threading
|
|
12
|
+
import urllib.error
|
|
13
|
+
import urllib.request
|
|
14
|
+
|
|
15
|
+
from PIL import Image
|
|
16
|
+
from trillboards_detector.colors import detection_color_fractions
|
|
17
|
+
from trillboards_detector.detections import Detection, DetectionBatch
|
|
18
|
+
from trillboards_detector.server import DetectorServer
|
|
19
|
+
|
|
20
|
+
SHA = "c" * 64
|
|
21
|
+
UNIFORM = {"version": 1, "minScore": .25, "maxBoxes": 32, "hue": [[0, 10], [240, 255]],
|
|
22
|
+
"minSaturation": 100, "minValue": 60}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Source:
|
|
26
|
+
state = "ready"
|
|
27
|
+
|
|
28
|
+
def __init__(self, detections):
|
|
29
|
+
self.detections, self.calls = detections, 0
|
|
30
|
+
|
|
31
|
+
def info(self):
|
|
32
|
+
return {"state": "ready"}
|
|
33
|
+
|
|
34
|
+
def resolve_classes(self, classes):
|
|
35
|
+
return set(classes)
|
|
36
|
+
|
|
37
|
+
def detect(self, jpeg, min_confidence, wanted, *, expected_model=None):
|
|
38
|
+
self.calls += 1
|
|
39
|
+
if expected_model != {"modelId": "rfdetr_medium", "sha256": SHA}:
|
|
40
|
+
raise ValueError("unexpected selected artifact")
|
|
41
|
+
return DetectionBatch(list(self.detections), models=["rfdetr_medium"], model_hashes={"rfdetr_medium": SHA})
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def frame():
|
|
45
|
+
"""Left half grey, right half Ace red: a box over either half is all or nothing."""
|
|
46
|
+
image = Image.new("RGB", (160, 120), (128, 128, 128))
|
|
47
|
+
image.paste((210, 20, 30), (80, 0, 160, 120))
|
|
48
|
+
out = io.BytesIO()
|
|
49
|
+
image.save(out, format="JPEG", quality=95)
|
|
50
|
+
return out.getvalue()
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class DetectionColorsWireTest(unittest.TestCase):
|
|
54
|
+
def start(self, detections):
|
|
55
|
+
self.source = Source(detections)
|
|
56
|
+
self.server = DetectorServer(("127.0.0.1", 0), self.source, log_line=lambda _: None)
|
|
57
|
+
self.worker = threading.Thread(target=lambda: self.server.serve_forever(poll_interval=.01), daemon=True)
|
|
58
|
+
self.worker.start()
|
|
59
|
+
self.base = "http://127.0.0.1:" + str(self.server.server_port)
|
|
60
|
+
self.jpeg = frame()
|
|
61
|
+
|
|
62
|
+
def tearDown(self):
|
|
63
|
+
self.server.shutdown()
|
|
64
|
+
self.server.server_close()
|
|
65
|
+
self.worker.join()
|
|
66
|
+
|
|
67
|
+
def post(self, **changes):
|
|
68
|
+
body = {"image_b64": base64.b64encode(self.jpeg).decode(), "classes": ["person", "tv"],
|
|
69
|
+
"min_confidence": .25, "expected_model": {"modelId": "rfdetr_medium", "sha256": SHA},
|
|
70
|
+
"detection_colors": UNIFORM, **changes}
|
|
71
|
+
body = {key: value for key, value in body.items() if value is not None}
|
|
72
|
+
request = urllib.request.Request(self.base + "/detect", data=json.dumps(body).encode(),
|
|
73
|
+
headers={"Content-Type": "application/json"})
|
|
74
|
+
try:
|
|
75
|
+
with urllib.request.urlopen(request, timeout=5) as r:
|
|
76
|
+
return r.status, json.load(r)
|
|
77
|
+
except urllib.error.HTTPError as e:
|
|
78
|
+
return e.code, json.load(e)
|
|
79
|
+
|
|
80
|
+
def test_each_confident_person_box_gets_its_uniform_share_keyed_by_detection_index(self):
|
|
81
|
+
self.start([Detection("tv", .9, 0, 0, 20, 20), Detection("person", .4, 10, 10, 40, 80),
|
|
82
|
+
Detection("person", .9, 100, 10, 40, 80), Detection("person", .2, 90, 0, 60, 100)])
|
|
83
|
+
status, body = self.post()
|
|
84
|
+
self.assertEqual(status, 200)
|
|
85
|
+
colors = body["detection_colors"]
|
|
86
|
+
self.assertEqual(colors["imageSha256"], hashlib.sha256(self.jpeg).hexdigest())
|
|
87
|
+
self.assertEqual(colors["frameSize"], {"width": 160, "height": 120})
|
|
88
|
+
self.assertEqual(colors["request"], UNIFORM)
|
|
89
|
+
# Highest score first; the 0.2 box is below minScore and the tv is not a person.
|
|
90
|
+
self.assertEqual([p["detectionIndex"] for p in colors["people"]], [2, 1])
|
|
91
|
+
self.assertGreater(colors["people"][0]["fraction"], .95)
|
|
92
|
+
self.assertLess(colors["people"][1]["fraction"], .05)
|
|
93
|
+
|
|
94
|
+
def test_the_service_number_is_the_measured_arithmetic(self):
|
|
95
|
+
self.start([Detection("person", .9, 70.6, 5.2, 40.9, 60.4)])
|
|
96
|
+
status, body = self.post()
|
|
97
|
+
self.assertEqual(status, 200)
|
|
98
|
+
_, expected = detection_color_fractions(self.jpeg, [[70.6, 5.2, 40.9, 60.4]], UNIFORM)
|
|
99
|
+
self.assertEqual(body["detection_colors"]["people"][0]["fraction"], expected[0])
|
|
100
|
+
# int() truncation of the float box, as measured: columns 70..110, 9 grey of 40.
|
|
101
|
+
self.assertAlmostEqual(expected[0], 31 / 40, delta=.03)
|
|
102
|
+
|
|
103
|
+
def test_a_frame_with_no_person_has_an_empty_list_not_a_missing_one(self):
|
|
104
|
+
self.start([Detection("tv", .9, 0, 0, 20, 20)])
|
|
105
|
+
status, body = self.post()
|
|
106
|
+
self.assertEqual(status, 200)
|
|
107
|
+
self.assertEqual(body["detection_colors"]["people"], [])
|
|
108
|
+
|
|
109
|
+
def test_an_ambiguous_or_unverified_request_is_refused_before_inference(self):
|
|
110
|
+
self.start([Detection("person", .9, 100, 10, 40, 80)])
|
|
111
|
+
bad = [{"expected_model": None}, {"classes": ["tv"]},
|
|
112
|
+
{"detection_colors": {**UNIFORM, "version": 2}},
|
|
113
|
+
{"detection_colors": {**UNIFORM, "minScore": 0}},
|
|
114
|
+
{"detection_colors": {**UNIFORM, "maxBoxes": 33}},
|
|
115
|
+
{"detection_colors": {**UNIFORM, "hue": []}},
|
|
116
|
+
{"detection_colors": {**UNIFORM, "hue": [[10, 0]]}},
|
|
117
|
+
{"detection_colors": {**UNIFORM, "hue": [[0, 256]]}},
|
|
118
|
+
{"detection_colors": {**UNIFORM, "minSaturation": 99.5}},
|
|
119
|
+
{"detection_colors": {**UNIFORM, "extra": 1}}]
|
|
120
|
+
for change in bad:
|
|
121
|
+
status, body = self.post(**change)
|
|
122
|
+
self.assertEqual(status, 400, change)
|
|
123
|
+
self.assertNotIn("detections", body)
|
|
124
|
+
self.assertEqual(self.source.calls, 0)
|
|
125
|
+
|
|
126
|
+
def test_an_unrequested_colour_task_is_absent(self):
|
|
127
|
+
self.start([Detection("person", .9, 100, 10, 40, 80)])
|
|
128
|
+
status, body = self.post(detection_colors=None)
|
|
129
|
+
self.assertEqual(status, 200)
|
|
130
|
+
self.assertNotIn("detection_colors", body)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
if __name__ == "__main__":
|
|
134
|
+
unittest.main()
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""Colour fractions inside person detections, on the original frame.
|
|
2
|
+
|
|
3
|
+
A uniform is the cheapest staff cue a ceiling camera sees: the Texas paint
|
|
4
|
+
counter's staff wear the store's red vest or shirt, its customers almost never
|
|
5
|
+
do. The connector decides "is a staff member here" from the share of a
|
|
6
|
+
person's box that is uniform-coloured; this module measures that share and
|
|
7
|
+
nothing else. It runs no model and makes no decision.
|
|
8
|
+
|
|
9
|
+
The arithmetic is the one the 2026-11-04 measurement used
|
|
10
|
+
(docs/runbooks/cctv-detector-tier.md section 5b): Pillow decodes the original
|
|
11
|
+
JPEG, converts it to Pillow's 8-bit HSV, and a pixel counts when its hue is in
|
|
12
|
+
one of the requested ranges and its saturation and value reach the floors. The
|
|
13
|
+
box is the detector's own float box truncated to whole pixels and clipped to
|
|
14
|
+
the frame, exactly as measured, so a re-measurement through this service gives
|
|
15
|
+
the same number to the last digit.
|
|
16
|
+
"""
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import io
|
|
20
|
+
import math
|
|
21
|
+
|
|
22
|
+
#: A request is a closed contract: anything else is refused before decoding.
|
|
23
|
+
MAX_COLOR_BOXES = 32
|
|
24
|
+
MAX_HUE_RANGES = 4
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def validate_color_request(value):
|
|
28
|
+
"""`detection_colors` -> the same dict, or ValueError."""
|
|
29
|
+
if (not isinstance(value, dict)
|
|
30
|
+
or set(value) != {"version", "minScore", "maxBoxes", "hue", "minSaturation", "minValue"}
|
|
31
|
+
or type(value["version"]) is not int or value["version"] != 1
|
|
32
|
+
or isinstance(value["minScore"], bool) or not isinstance(value["minScore"], (int, float))
|
|
33
|
+
or not math.isfinite(value["minScore"]) or not 0 < value["minScore"] <= 1
|
|
34
|
+
or type(value["maxBoxes"]) is not int or not 1 <= value["maxBoxes"] <= MAX_COLOR_BOXES
|
|
35
|
+
or type(value["minSaturation"]) is not int or not 0 <= value["minSaturation"] <= 255
|
|
36
|
+
or type(value["minValue"]) is not int or not 0 <= value["minValue"] <= 255
|
|
37
|
+
or not isinstance(value["hue"], list) or not 1 <= len(value["hue"]) <= MAX_HUE_RANGES
|
|
38
|
+
or any(not isinstance(r, list) or len(r) != 2 or any(type(v) is not int for v in r)
|
|
39
|
+
or not 0 <= r[0] <= r[1] <= 255 for r in value["hue"])):
|
|
40
|
+
raise ValueError(
|
|
41
|
+
"detection_colors needs version 1, minScore in (0, 1], maxBoxes 1..%d, "
|
|
42
|
+
"1..%d hue ranges of whole 0..255 values, and whole saturation/value floors"
|
|
43
|
+
% (MAX_COLOR_BOXES, MAX_HUE_RANGES))
|
|
44
|
+
return {**value, "hue": [list(r) for r in value["hue"]]}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def color_box_indices(detections, request):
|
|
48
|
+
"""Person detections at or above minScore, highest score first, at most maxBoxes."""
|
|
49
|
+
people = [(index, d) for index, d in enumerate(detections)
|
|
50
|
+
if d.label == "person" and d.confidence >= request["minScore"]]
|
|
51
|
+
people.sort(key=lambda item: (-item[1].confidence, item[0]))
|
|
52
|
+
return [index for index, _ in people[:request["maxBoxes"]]]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def detection_color_fractions(jpeg, boxes, request):
|
|
56
|
+
"""Fraction of each [x, y, width, height] box whose pixels match the request."""
|
|
57
|
+
import numpy as np
|
|
58
|
+
from PIL import Image
|
|
59
|
+
with Image.open(io.BytesIO(jpeg)) as image:
|
|
60
|
+
if image.format != "JPEG" or image.width * image.height > 16777216:
|
|
61
|
+
raise ValueError("colour fractions need a bounded original JPEG")
|
|
62
|
+
hsv = np.asarray(image.convert("HSV")).astype(np.int16)
|
|
63
|
+
height, width = hsv.shape[0], hsv.shape[1]
|
|
64
|
+
hue, sat, val = hsv[..., 0], hsv[..., 1], hsv[..., 2]
|
|
65
|
+
in_hue = np.zeros(hue.shape, dtype=bool)
|
|
66
|
+
for low, high in request["hue"]:
|
|
67
|
+
in_hue |= (hue >= low) & (hue <= high)
|
|
68
|
+
match = in_hue & (sat >= request["minSaturation"]) & (val >= request["minValue"])
|
|
69
|
+
fractions = []
|
|
70
|
+
for x, y, w, h in boxes:
|
|
71
|
+
x0, x1 = int(max(0, x)), int(min(width, x + w))
|
|
72
|
+
y0, y1 = int(max(0, y)), int(min(height, y + h))
|
|
73
|
+
cell = match[y0:max(y1, y0 + 1), x0:max(x1, x0 + 1)]
|
|
74
|
+
fractions.append(round(float(cell.mean()), 4) if cell.size else 0.0)
|
|
75
|
+
return (width, height), fractions
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def build_color_response(request, indices, fractions, image_sha256, frame_size):
|
|
79
|
+
if len(indices) != len(fractions) or any(
|
|
80
|
+
isinstance(f, bool) or not isinstance(f, float) or not 0 <= f <= 1 for f in fractions):
|
|
81
|
+
raise ValueError("colour fractions differ from the requested person boxes")
|
|
82
|
+
return {"version": 1, "imageSha256": image_sha256,
|
|
83
|
+
"frameSize": {"width": frame_size[0], "height": frame_size[1]},
|
|
84
|
+
"request": request,
|
|
85
|
+
"people": [{"detectionIndex": i, "fraction": f} for i, f in zip(indices, fractions)]}
|
|
@@ -38,6 +38,7 @@ from .actor_tracking import TrackingError, validate_tracking_request
|
|
|
38
38
|
from .actor_identity import MODEL_ID as APPEARANCE_MODEL_ID, MODEL_SHA256 as APPEARANCE_SHA256, PREPROCESSING as APPEARANCE_PREPROCESSING, checked_appearance
|
|
39
39
|
from .tasks import RTMPOSE_MODEL_ID, RTMPOSE_SHA256, RTMPOSE_PREPROCESSING, COCO17
|
|
40
40
|
from .actor_action_wire import parse_actor_action_request, validate_actor_action_response
|
|
41
|
+
from .colors import validate_color_request
|
|
41
42
|
from ._version import VERSION
|
|
42
43
|
from .errors import DetectorNotReady, ModelVerificationError, UnknownClasses
|
|
43
44
|
|
|
@@ -273,6 +274,17 @@ def parse_detection_pose(raw: bytes):
|
|
|
273
274
|
return value
|
|
274
275
|
|
|
275
276
|
|
|
277
|
+
def parse_detection_colors(raw: bytes):
|
|
278
|
+
"""`detection_colors`: uniform-colour share of each confident person box."""
|
|
279
|
+
body = json.loads(raw.decode("utf-8"))
|
|
280
|
+
if "detection_colors" not in body:
|
|
281
|
+
return None
|
|
282
|
+
try:
|
|
283
|
+
return validate_color_request(body["detection_colors"])
|
|
284
|
+
except ValueError as err:
|
|
285
|
+
raise WireError(400, str(err)) from None
|
|
286
|
+
|
|
287
|
+
|
|
276
288
|
def parse_appearance_model(raw: bytes):
|
|
277
289
|
body = json.loads(raw.decode("utf-8"))
|
|
278
290
|
if "appearance_model" not in body:
|
|
@@ -449,6 +461,7 @@ class DetectorHandler(BaseHTTPRequestHandler):
|
|
|
449
461
|
pose_model = parse_pose_model(raw)
|
|
450
462
|
detection_pose = parse_detection_pose(raw)
|
|
451
463
|
appearance_model = parse_appearance_model(raw)
|
|
464
|
+
detection_colors = parse_detection_colors(raw)
|
|
452
465
|
tracking = json.loads(raw.decode("utf-8")).get("tracking")
|
|
453
466
|
if detection_pose is not None and (pose_model is None or tracking is not None):
|
|
454
467
|
raise WireError(400, "pose_detections needs a pinned pose_model and no tracking")
|
|
@@ -480,6 +493,12 @@ class DetectorHandler(BaseHTTPRequestHandler):
|
|
|
480
493
|
if requested is not None and "person" not in requested:
|
|
481
494
|
raise WireError(400, "pose_detections requires person detections")
|
|
482
495
|
frame_size = original_frame_size(jpeg)
|
|
496
|
+
if detection_colors is not None:
|
|
497
|
+
if expected_model is None:
|
|
498
|
+
raise WireError(400, "detection_colors requires a verified selected detector")
|
|
499
|
+
if requested is not None and "person" not in requested:
|
|
500
|
+
raise WireError(400, "detection_colors requires person detections")
|
|
501
|
+
original_frame_size(jpeg)
|
|
483
502
|
except WireError as err:
|
|
484
503
|
self._json(err.status, {"error": err.message})
|
|
485
504
|
return
|
|
@@ -549,6 +568,14 @@ class DetectorHandler(BaseHTTPRequestHandler):
|
|
|
549
568
|
boxes.append([detection.x, detection.y, detection.x + detection.width, detection.y + detection.height])
|
|
550
569
|
result = loader.estimate_pose(jpeg, boxes, pose_model)
|
|
551
570
|
body["pose"] = build_pose_response(result, body["tracking"], frame_size)
|
|
571
|
+
if detection_colors is not None:
|
|
572
|
+
from .colors import build_color_response, color_box_indices, detection_color_fractions
|
|
573
|
+
indices = color_box_indices(batch.detections, detection_colors)
|
|
574
|
+
size, fractions = detection_color_fractions(
|
|
575
|
+
jpeg, [[d.x, d.y, d.width, d.height] for d in (batch.detections[i] for i in indices)],
|
|
576
|
+
detection_colors)
|
|
577
|
+
body["detection_colors"] = build_color_response(
|
|
578
|
+
detection_colors, indices, fractions, hashlib.sha256(jpeg).hexdigest(), size)
|
|
552
579
|
except ModelVerificationError as err:
|
|
553
580
|
self._json(409, {"error": str(err)})
|
|
554
581
|
return
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The detector service's `detection_colors` task: the share of each confident
|
|
3
|
+
* person box whose pixels are a requested colour, measured on the original
|
|
4
|
+
* frame with Pillow's 8-bit HSV (deploy/detector/trillboards_detector/colors.py).
|
|
5
|
+
* No model and no decision: the connector turns the share into "this person
|
|
6
|
+
* wears the store's uniform".
|
|
7
|
+
*/
|
|
8
|
+
export interface DetectionColorsRequest {
|
|
9
|
+
version: 1;
|
|
10
|
+
minScore: number;
|
|
11
|
+
maxBoxes: number;
|
|
12
|
+
hue: Array<[number, number]>;
|
|
13
|
+
minSaturation: number;
|
|
14
|
+
minValue: number;
|
|
15
|
+
}
|
|
16
|
+
export interface DetectionColorsResult {
|
|
17
|
+
version: 1;
|
|
18
|
+
imageSha256: string;
|
|
19
|
+
frameSize: {
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
};
|
|
23
|
+
request: DetectionColorsRequest;
|
|
24
|
+
people: Array<{
|
|
25
|
+
detectionIndex: number;
|
|
26
|
+
fraction: number;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
export declare const MAX_COLOR_BOXES = 32;
|
|
30
|
+
export declare function validateDetectionColorsRequest(value: unknown): DetectionColorsRequest;
|
|
31
|
+
/** The service's own box selection: person boxes at or above minScore, highest score first. */
|
|
32
|
+
export declare function colorBoxIndices(detections: ReadonlyArray<{
|
|
33
|
+
label: string;
|
|
34
|
+
confidence: number;
|
|
35
|
+
}>, request: DetectionColorsRequest): number[];
|
|
36
|
+
/** Exactly the eligible people of this original frame, each with a share in [0,1]. */
|
|
37
|
+
export declare function parseDetectionColorsResult(value: unknown, request: DetectionColorsRequest, jpeg: Buffer, originalSize: {
|
|
38
|
+
width: number;
|
|
39
|
+
height: number;
|
|
40
|
+
}, detections: ReadonlyArray<{
|
|
41
|
+
label: string;
|
|
42
|
+
confidence: number;
|
|
43
|
+
}>): DetectionColorsResult;
|
|
44
|
+
//# sourceMappingURL=DetectionColors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DetectionColors.d.ts","sourceRoot":"","sources":["../src/DetectionColors.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAC,CAAC,CAAC;IAAC,QAAQ,EAAC,MAAM,CAAC;IAAC,QAAQ,EAAC,MAAM,CAAC;IAC5C,GAAG,EAAC,KAAK,CAAC,CAAC,MAAM,EAAC,MAAM,CAAC,CAAC,CAAC;IAAC,aAAa,EAAC,MAAM,CAAC;IAAC,QAAQ,EAAC,MAAM,CAAC;CACnE;AACD,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAC,CAAC,CAAC;IAAC,WAAW,EAAC,MAAM,CAAC;IAAC,SAAS,EAAC;QAAC,KAAK,EAAC,MAAM,CAAC;QAAA,MAAM,EAAC,MAAM,CAAA;KAAC,CAAC;IACtE,OAAO,EAAC,sBAAsB,CAAC;IAC/B,MAAM,EAAC,KAAK,CAAC;QAAC,cAAc,EAAC,MAAM,CAAC;QAAA,QAAQ,EAAC,MAAM,CAAA;KAAC,CAAC,CAAC;CACvD;AACD,eAAO,MAAM,eAAe,KAAG,CAAC;AAKhC,wBAAgB,8BAA8B,CAAC,KAAK,EAAC,OAAO,GAAE,sBAAsB,CAUnF;AAED,+FAA+F;AAC/F,wBAAgB,eAAe,CAAC,UAAU,EAAC,aAAa,CAAC;IAAC,KAAK,EAAC,MAAM,CAAC;IAAA,UAAU,EAAC,MAAM,CAAA;CAAC,CAAC,EACxF,OAAO,EAAC,sBAAsB,GAAE,MAAM,EAAE,CAKzC;AAED,sFAAsF;AACtF,wBAAgB,0BAA0B,CAAC,KAAK,EAAC,OAAO,EAAC,OAAO,EAAC,sBAAsB,EAAC,IAAI,EAAC,MAAM,EACjG,YAAY,EAAC;IAAC,KAAK,EAAC,MAAM,CAAC;IAAA,MAAM,EAAC,MAAM,CAAA;CAAC,EAAC,UAAU,EAAC,aAAa,CAAC;IAAC,KAAK,EAAC,MAAM,CAAC;IAAA,UAAU,EAAC,MAAM,CAAA;CAAC,CAAC,GAAE,qBAAqB,CAe5H"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_COLOR_BOXES = void 0;
|
|
4
|
+
exports.validateDetectionColorsRequest = validateDetectionColorsRequest;
|
|
5
|
+
exports.colorBoxIndices = colorBoxIndices;
|
|
6
|
+
exports.parseDetectionColorsResult = parseDetectionColorsResult;
|
|
7
|
+
const crypto_1 = require("crypto");
|
|
8
|
+
const util_1 = require("util");
|
|
9
|
+
exports.MAX_COLOR_BOXES = 32;
|
|
10
|
+
const keys = (v, want) => !!v && typeof v === 'object' && !Array.isArray(v) && Object.keys(v).sort().join(',') === want;
|
|
11
|
+
const finite = (v) => typeof v === 'number' && Number.isFinite(v);
|
|
12
|
+
const byte = (v) => Number.isSafeInteger(v) && v >= 0 && v <= 255;
|
|
13
|
+
function validateDetectionColorsRequest(value) {
|
|
14
|
+
const v = value;
|
|
15
|
+
if (!keys(v, 'hue,maxBoxes,minSaturation,minScore,minValue,version') || v.version !== 1
|
|
16
|
+
|| !finite(v.minScore) || v.minScore <= 0 || v.minScore > 1
|
|
17
|
+
|| !Number.isSafeInteger(v.maxBoxes) || v.maxBoxes < 1 || v.maxBoxes > exports.MAX_COLOR_BOXES
|
|
18
|
+
|| !byte(v.minSaturation) || !byte(v.minValue)
|
|
19
|
+
|| !Array.isArray(v.hue) || v.hue.length < 1 || v.hue.length > 4
|
|
20
|
+
|| v.hue.some(r => !Array.isArray(r) || r.length !== 2 || !byte(r[0]) || !byte(r[1]) || r[0] > r[1]))
|
|
21
|
+
throw Error('Invalid detection colour request');
|
|
22
|
+
return JSON.parse(JSON.stringify(v));
|
|
23
|
+
}
|
|
24
|
+
/** The service's own box selection: person boxes at or above minScore, highest score first. */
|
|
25
|
+
function colorBoxIndices(detections, request) {
|
|
26
|
+
return detections.map((d, index) => ({ d, index }))
|
|
27
|
+
.filter(({ d }) => d.label === 'person' && d.confidence >= request.minScore)
|
|
28
|
+
.sort((a, b) => b.d.confidence - a.d.confidence || a.index - b.index)
|
|
29
|
+
.slice(0, request.maxBoxes).map(e => e.index);
|
|
30
|
+
}
|
|
31
|
+
/** Exactly the eligible people of this original frame, each with a share in [0,1]. */
|
|
32
|
+
function parseDetectionColorsResult(value, request, jpeg, originalSize, detections) {
|
|
33
|
+
validateDetectionColorsRequest(request);
|
|
34
|
+
const v = value;
|
|
35
|
+
if (!keys(v, 'frameSize,imageSha256,people,request,version') || v.version !== 1
|
|
36
|
+
|| v.imageSha256 !== (0, crypto_1.createHash)('sha256').update(jpeg).digest('hex')
|
|
37
|
+
|| !keys(v.frameSize, 'height,width') || v.frameSize.width !== originalSize.width
|
|
38
|
+
|| v.frameSize.height !== originalSize.height || !(0, util_1.isDeepStrictEqual)(v.request, request)
|
|
39
|
+
|| !Array.isArray(v.people))
|
|
40
|
+
throw Error('Invalid colour proof for the original detected frame');
|
|
41
|
+
const eligible = colorBoxIndices(detections, request);
|
|
42
|
+
if (v.people.length !== eligible.length)
|
|
43
|
+
throw Error('Colours do not cover exactly the confident people');
|
|
44
|
+
v.people.forEach((row, i) => {
|
|
45
|
+
if (!keys(row, 'detectionIndex,fraction') || row.detectionIndex !== eligible[i]
|
|
46
|
+
|| !finite(row.fraction) || row.fraction < 0 || row.fraction > 1)
|
|
47
|
+
throw Error('Invalid detection colour association');
|
|
48
|
+
});
|
|
49
|
+
return JSON.parse(JSON.stringify(v));
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=DetectionColors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DetectionColors.js","sourceRoot":"","sources":["../src/DetectionColors.ts"],"names":[],"mappings":";;;AAwBA,wEAUC;AAGD,0CAMC;AAGD,gEAgBC;AA9DD,mCAAkC;AAClC,+BAAuC;AAkB1B,QAAA,eAAe,GAAC,EAAE,CAAC;AAChC,MAAM,IAAI,GAAC,CAAC,CAAS,EAAC,IAAW,EAAC,EAAE,CAAA,CAAC,CAAC,CAAC,IAAE,OAAO,CAAC,KAAG,QAAQ,IAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,KAAG,IAAI,CAAC;AACxH,MAAM,MAAM,GAAC,CAAC,CAAS,EAAa,EAAE,CAAA,OAAO,CAAC,KAAG,QAAQ,IAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AAC9E,MAAM,IAAI,GAAC,CAAC,CAAS,EAAC,EAAE,CAAA,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,IAAG,CAAY,IAAE,CAAC,IAAG,CAAY,IAAE,GAAG,CAAC;AAEtF,SAAgB,8BAA8B,CAAC,KAAa;IAC1D,MAAM,CAAC,GAAC,KAA+B,CAAC;IACxC,IAAG,CAAC,IAAI,CAAC,CAAC,EAAC,sDAAsD,CAAC,IAAE,CAAC,CAAC,OAAO,KAAG,CAAC;WAC7E,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAE,CAAC,CAAC,QAAQ,IAAE,CAAC,IAAE,CA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IACtG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,EAAC,CAAC,EAAC,EAAE;QACxB,IAAG,CAAC,IAAI,CAAC,GAAG,EAAC,yBAAyB,CAAC,IAAE,GAAG,CAAC,cAAc,KAAG,QAAQ,CAAC,CAAC,CAAC;eACrE,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAE,GAAG,CAAC,QAAQ,GAAC,CAAC,IAAE,GAAG,CAAC,QAAQ,GAAC,CAAC;YAAC,MAAM,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAChH,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import type { Detection } from './LocalDetectorClient';
|
|
2
|
+
import type { DetectionColorsRequest, DetectionColorsResult } from './DetectionColors';
|
|
3
|
+
import { type NormalizedPoint } from './zoneContainment';
|
|
4
|
+
/**
|
|
5
|
+
* Declared website questions the box's own detector answers on the ORIGINAL
|
|
6
|
+
* frame, so the language model is not asked on every frame. Server-selected per
|
|
7
|
+
* camera (retained profile `detectorFields`, CCTV_DETECTOR_FIELDS_SCREENS) and
|
|
8
|
+
* pinned: every number below is the one measured. The question stays declared;
|
|
9
|
+
* only who answers it changes.
|
|
10
|
+
*
|
|
11
|
+
* Measured 2026-11-04 on the Texas store (docs/runbooks/cctv-detector-tier.md
|
|
12
|
+
* section 5b), the pinned RF-DETR Medium through the detector service's own
|
|
13
|
+
* code; 324 ms detection per frame on 4 pinned cores, ~0.6 s on the Texas box:
|
|
14
|
+
*
|
|
15
|
+
* unattended_customer_v1 paint counter, 3,153 reviewed frames (09:18-14:57),
|
|
16
|
+
* every person hand-labelled staff or customer. Per frame: 56 of 63
|
|
17
|
+
* customer-alone frames caught, 6 false (90% precision, 89% recall); 1
|
|
18
|
+
* route alert in 5.6 store hours. Gemma as deployed: 0 of 63.
|
|
19
|
+
* detected_labels_v1 the detector's raw object list for a profile's
|
|
20
|
+
* `detected_objects` raw-output field (Gemma answered [] on 56 of 63 frames
|
|
21
|
+
* with cars parked in them).
|
|
22
|
+
* vehicle_arrival_gate_v1 a parked-vehicle question Gemma still answers, asked
|
|
23
|
+
* only when a vehicle has newly stopped (or one left while the answer was
|
|
24
|
+
* yes) and reused otherwise: 109 questions in 12 store hours of parking-lot
|
|
25
|
+
* video instead of one on every reviewed frame.
|
|
26
|
+
*/
|
|
27
|
+
declare const RF_SHA = "8e8197112112b79d7cc5d0a94ecef659c05317a658aadc7c7643374c539d7615";
|
|
28
|
+
type Box = {
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
width: number;
|
|
32
|
+
height: number;
|
|
33
|
+
};
|
|
34
|
+
export interface UnattendedCustomerMethod {
|
|
35
|
+
field: string;
|
|
36
|
+
method: 'unattended_customer_v1';
|
|
37
|
+
minPersonConfidence: 0.25;
|
|
38
|
+
screenLabels: ['laptop', 'tv'];
|
|
39
|
+
screenContainment: 0.8;
|
|
40
|
+
maxPeople: 32;
|
|
41
|
+
uniform: {
|
|
42
|
+
hue: [[0, 10], [240, 255]];
|
|
43
|
+
minSaturation: 100;
|
|
44
|
+
minValue: 60;
|
|
45
|
+
staffFraction: 0.08;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export interface DetectedLabelsMethod {
|
|
49
|
+
field: string;
|
|
50
|
+
method: 'detected_labels_v1';
|
|
51
|
+
minConfidence: 0.5;
|
|
52
|
+
}
|
|
53
|
+
export interface VehicleArrivalGateMethod {
|
|
54
|
+
field: string;
|
|
55
|
+
method: 'vehicle_arrival_gate_v1';
|
|
56
|
+
vehicleLabels: ['bus', 'car', 'motorcycle', 'truck'];
|
|
57
|
+
minConfidence: 0.5;
|
|
58
|
+
minArea: 0.04;
|
|
59
|
+
sameVehicleIou: 0.6;
|
|
60
|
+
stationaryIou: 0.8;
|
|
61
|
+
minStationaryMs: 10000;
|
|
62
|
+
maxGapMs: 120000;
|
|
63
|
+
}
|
|
64
|
+
export type DetectorFieldMethod = UnattendedCustomerMethod | DetectedLabelsMethod | VehicleArrivalGateMethod;
|
|
65
|
+
export interface DetectorFieldsPolicy {
|
|
66
|
+
version: 1;
|
|
67
|
+
detector: {
|
|
68
|
+
modelId: 'rfdetr_medium';
|
|
69
|
+
format: 'onnx';
|
|
70
|
+
sha256: typeof RF_SHA;
|
|
71
|
+
};
|
|
72
|
+
fields: DetectorFieldMethod[];
|
|
73
|
+
}
|
|
74
|
+
/** Only the exact pinned methods; anything else is refused, never adapted. */
|
|
75
|
+
export declare function parseDetectorFields(value: unknown): DetectorFieldsPolicy | undefined;
|
|
76
|
+
/** One detector call serves every detector-answered question of the frame. */
|
|
77
|
+
export declare function detectorFieldsRequest(policy: DetectorFieldsPolicy): {
|
|
78
|
+
classes: string[];
|
|
79
|
+
minConfidence: number;
|
|
80
|
+
expectedModel: {
|
|
81
|
+
modelId: string;
|
|
82
|
+
sha256: string;
|
|
83
|
+
};
|
|
84
|
+
colors?: DetectionColorsRequest;
|
|
85
|
+
};
|
|
86
|
+
export declare const policySha256: (policy: DetectorFieldsPolicy) => string;
|
|
87
|
+
export interface UnattendedCustomerTrace {
|
|
88
|
+
method: 'unattended_customer_v1';
|
|
89
|
+
imageSha256: string;
|
|
90
|
+
policySha256: string;
|
|
91
|
+
/** Person boxes at or above the person bar; pictures are people inside a detected screen. */
|
|
92
|
+
people: number;
|
|
93
|
+
pictures: number[];
|
|
94
|
+
staff: Array<{
|
|
95
|
+
index: number;
|
|
96
|
+
fraction: number;
|
|
97
|
+
}>;
|
|
98
|
+
customers: Array<{
|
|
99
|
+
index: number;
|
|
100
|
+
fraction: number;
|
|
101
|
+
}>;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* A customer is in view and no staff member is: a person box that is not a
|
|
105
|
+
* picture on a screen and does not wear the store's uniform colour, and no box
|
|
106
|
+
* that does. Pure; the same inputs always give the same answer and trace.
|
|
107
|
+
*
|
|
108
|
+
* Staff are counted anywhere in the frame (a staff member at the far shelf is
|
|
109
|
+
* attending the floor); a drawn polygon limits only where a customer stands
|
|
110
|
+
* (box bottom-centre, as every zone rule here). The 60-second wait is the
|
|
111
|
+
* route's own wait/recheck, not this frame's answer.
|
|
112
|
+
*/
|
|
113
|
+
export declare function decideUnattendedCustomer(input: {
|
|
114
|
+
jpeg: Buffer;
|
|
115
|
+
policy: DetectorFieldsPolicy;
|
|
116
|
+
method: UnattendedCustomerMethod;
|
|
117
|
+
frame: {
|
|
118
|
+
width: number;
|
|
119
|
+
height: number;
|
|
120
|
+
};
|
|
121
|
+
detections: ReadonlyArray<Detection>;
|
|
122
|
+
colors: DetectionColorsResult;
|
|
123
|
+
region?: ReadonlyArray<NormalizedPoint>;
|
|
124
|
+
}): {
|
|
125
|
+
value: boolean;
|
|
126
|
+
trace: UnattendedCustomerTrace;
|
|
127
|
+
};
|
|
128
|
+
export interface DetectedLabelsTrace {
|
|
129
|
+
method: 'detected_labels_v1';
|
|
130
|
+
imageSha256: string;
|
|
131
|
+
policySha256: string;
|
|
132
|
+
labels: Array<{
|
|
133
|
+
label: string;
|
|
134
|
+
count: number;
|
|
135
|
+
maxConfidence: number;
|
|
136
|
+
}>;
|
|
137
|
+
}
|
|
138
|
+
/** The detector's own object list: every class it found at or above the bar, once. */
|
|
139
|
+
export declare function decideDetectedLabels(input: {
|
|
140
|
+
jpeg: Buffer;
|
|
141
|
+
policy: DetectorFieldsPolicy;
|
|
142
|
+
method: DetectedLabelsMethod;
|
|
143
|
+
detections: ReadonlyArray<Detection>;
|
|
144
|
+
}): {
|
|
145
|
+
value: string[];
|
|
146
|
+
trace: DetectedLabelsTrace;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* The vehicles the remembered answer describes. One per camera field, in memory
|
|
150
|
+
* only: losing it costs one extra question, never a wrong answer.
|
|
151
|
+
*/
|
|
152
|
+
export interface VehicleGateMemory {
|
|
153
|
+
version: 1;
|
|
154
|
+
lastAtMs: number;
|
|
155
|
+
/** Every vehicle box of the previous frame and when it first stood there. */
|
|
156
|
+
tracks: Array<{
|
|
157
|
+
box: Box;
|
|
158
|
+
firstSeenAtMs: number;
|
|
159
|
+
}>;
|
|
160
|
+
/** The parked vehicles the answer covers; one unseen for under minStationaryMs is still parked. */
|
|
161
|
+
parked: Array<{
|
|
162
|
+
box: Box;
|
|
163
|
+
lastSeenAtMs: number;
|
|
164
|
+
}>;
|
|
165
|
+
answer: boolean;
|
|
166
|
+
answerFrom: {
|
|
167
|
+
imageSha256: string;
|
|
168
|
+
capturedAtMs: number;
|
|
169
|
+
} | null;
|
|
170
|
+
}
|
|
171
|
+
export interface VehicleGateTrace {
|
|
172
|
+
method: 'vehicle_arrival_gate_v1';
|
|
173
|
+
imageSha256: string;
|
|
174
|
+
policySha256: string;
|
|
175
|
+
action: 'no_vehicle' | 'no_parked_vehicle' | 'reuse' | 'ask';
|
|
176
|
+
vehicles: number;
|
|
177
|
+
stationary: number;
|
|
178
|
+
parked: number;
|
|
179
|
+
arrivals: number;
|
|
180
|
+
departures: number;
|
|
181
|
+
answerFrom: {
|
|
182
|
+
imageSha256: string;
|
|
183
|
+
capturedAtMs: number;
|
|
184
|
+
} | null;
|
|
185
|
+
}
|
|
186
|
+
export interface VehicleGatePlan {
|
|
187
|
+
ask: boolean;
|
|
188
|
+
value?: boolean;
|
|
189
|
+
trace: VehicleGateTrace;
|
|
190
|
+
/** The memory after this frame; `answer` is the model's answer when `ask`. */
|
|
191
|
+
commit: (answer?: boolean) => VehicleGateMemory;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Ask the language model only when a vehicle has newly stopped (in the same
|
|
195
|
+
* place for minStationaryMs), or when a parked vehicle left while the answer was
|
|
196
|
+
* yes; otherwise reuse the answer for the vehicles still parked. No vehicle, or
|
|
197
|
+
* none parked, is a definite no: nothing parked can be parked backwards. A
|
|
198
|
+
* memory older than maxGapMs, or a frame not after it, starts afresh.
|
|
199
|
+
*/
|
|
200
|
+
export declare function planVehicleGate(input: {
|
|
201
|
+
jpeg: Buffer;
|
|
202
|
+
policy: DetectorFieldsPolicy;
|
|
203
|
+
method: VehicleArrivalGateMethod;
|
|
204
|
+
frame: {
|
|
205
|
+
width: number;
|
|
206
|
+
height: number;
|
|
207
|
+
};
|
|
208
|
+
detections: ReadonlyArray<Detection>;
|
|
209
|
+
capturedAtMs: number;
|
|
210
|
+
memory?: VehicleGateMemory;
|
|
211
|
+
}): VehicleGatePlan;
|
|
212
|
+
export {};
|
|
213
|
+
//# sourceMappingURL=DetectorFields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DetectorFields.d.ts","sourceRoot":"","sources":["../src/DetectorFields.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAC,sBAAsB,EAAE,qBAAqB,EAAC,MAAM,mBAAmB,CAAC;AACrF,OAAO,EAAiB,KAAK,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,QAAA,MAAM,MAAM,qEAAmE,CAAC;AAChF,KAAK,GAAG,GAAC;IAAC,CAAC,EAAC,MAAM,CAAC;IAAA,CAAC,EAAC,MAAM,CAAC;IAAA,KAAK,EAAC,MAAM,CAAC;IAAA,MAAM,EAAC,MAAM,CAAA;CAAC,CAAC;AAExD,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAC,MAAM,CAAC;IAAC,MAAM,EAAC,wBAAwB,CAAC;IAC9C,mBAAmB,EAAC,IAAI,CAAC;IAAC,YAAY,EAAC,CAAC,QAAQ,EAAC,IAAI,CAAC,CAAC;IAAC,iBAAiB,EAAC,GAAG,CAAC;IAAC,SAAS,EAAC,EAAE,CAAC;IAC5F,OAAO,EAAC;QAAC,GAAG,EAAC,CAAC,CAAC,CAAC,EAA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