feat(perception): sample OCR text foreground/background colors
Tests / Test apps.device-host-agent.tests.test_e2e.test_public_sdk_reports_fake_device_success_and_runtime_failure failed
Tests / Test apps.device-host-agent.tests.test_e2e.test_public_sdk_reports_fake_device_success_and_runtime_failure failed
PaddleOCR itself returns no color info, only text/bounds/confidence.
Add pixel-level post-processing in perception/ocr.py: crop the
screenshot to each OCR box, split pixels into two luminance clusters
via Otsu threshold, and treat the minority cluster as the text stroke
(foreground) and the majority as the background. New
SceneElement.foreground_color/background_color fields ("#rrggbb",
None when not OCR-sourced or sampling fails) round-trip through
to_dict/from_dict alongside the existing accessibility-state fields.
Planner system prompt documents the new fields as a secondary signal.
pillow is promoted from an implicit paddleocr transitive dependency to
an explicit direct dependency since perception/ocr.py now imports PIL
directly; uv.lock re-resolved with no version change (already locked
at 12.3.0).
This commit is contained in:
+9
-1
@@ -72,6 +72,7 @@ class Device:
|
||||
|
||||
|
||||
_STATE_FIELDS = ("enabled", "clickable", "selected", "checked", "focused")
|
||||
_COLOR_FIELDS = ("foreground_color", "background_color")
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -89,6 +90,11 @@ class SceneElement:
|
||||
selected: bool | None = None
|
||||
checked: bool | None = None
|
||||
focused: bool | None = None
|
||||
# Text/background color sampled from the screenshot pixels under the OCR
|
||||
# box ("#rrggbb"). None means unavailable (not OCR-sourced, or sampling
|
||||
# failed), not "no color".
|
||||
foreground_color: str | None = None
|
||||
background_color: str | None = None
|
||||
|
||||
@property
|
||||
def center(self) -> tuple[float, float]:
|
||||
@@ -104,7 +110,7 @@ class SceneElement:
|
||||
}
|
||||
if self.source:
|
||||
data["source"] = self.source
|
||||
for field_name in _STATE_FIELDS:
|
||||
for field_name in _STATE_FIELDS + _COLOR_FIELDS:
|
||||
value = getattr(self, field_name)
|
||||
if value is not None:
|
||||
data[field_name] = value
|
||||
@@ -124,6 +130,8 @@ class SceneElement:
|
||||
selected=data.get("selected"),
|
||||
checked=data.get("checked"),
|
||||
focused=data.get("focused"),
|
||||
foreground_color=data.get("foreground_color"),
|
||||
background_color=data.get("background_color"),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user