fix(demo): stabilize visualizer bbox and mask rendering
Align bbox coordinate handling across primary and fallback paths, normalize Both-mode raw mask rendering, and tighten demo result typing to reduce runtime/display inconsistencies.
This commit is contained in:
+24
-9
@@ -14,7 +14,7 @@ import logging
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
from typing import TYPE_CHECKING, Protocol, TextIO, cast, runtime_checkable
|
||||
from typing import TYPE_CHECKING, Protocol, TextIO, TypedDict, cast, runtime_checkable
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from types import TracebackType
|
||||
@@ -22,17 +22,31 @@ if TYPE_CHECKING:
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DemoResult(TypedDict):
|
||||
"""Typed result dictionary for demo pipeline output.
|
||||
|
||||
Contains classification result with frame metadata.
|
||||
"""
|
||||
|
||||
frame: int
|
||||
track_id: int
|
||||
label: str
|
||||
confidence: float
|
||||
window: int
|
||||
timestamp_ns: int
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class ResultPublisher(Protocol):
|
||||
"""Protocol for result publishers."""
|
||||
|
||||
def publish(self, result: dict[str, object]) -> None:
|
||||
def publish(self, result: DemoResult) -> None:
|
||||
"""
|
||||
Publish a result dictionary.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
result : dict[str, object]
|
||||
result : DemoResult
|
||||
Result data with keys: frame, track_id, label, confidence, window, timestamp_ns
|
||||
"""
|
||||
...
|
||||
@@ -54,13 +68,13 @@ class ConsolePublisher:
|
||||
"""
|
||||
self._output = output
|
||||
|
||||
def publish(self, result: dict[str, object]) -> None:
|
||||
def publish(self, result: DemoResult) -> None:
|
||||
"""
|
||||
Publish result as JSON line.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
result : dict[str, object]
|
||||
result : DemoResult
|
||||
Result data with keys: frame, track_id, label, confidence, window, timestamp_ns
|
||||
"""
|
||||
try:
|
||||
@@ -214,13 +228,13 @@ class NatsPublisher:
|
||||
logger.warning(f"Failed to connect to NATS at {self._nats_url}: {e}")
|
||||
return False
|
||||
|
||||
def publish(self, result: dict[str, object]) -> None:
|
||||
def publish(self, result: DemoResult) -> None:
|
||||
"""
|
||||
Publish result to NATS subject.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
result : dict[str, object]
|
||||
result : DemoResult
|
||||
Result data with keys: frame, track_id, label, confidence, window, timestamp_ns
|
||||
"""
|
||||
if not self._ensure_connected():
|
||||
@@ -239,6 +253,7 @@ class NatsPublisher:
|
||||
).encode("utf-8")
|
||||
_ = await self._nc.publish(self._subject, payload)
|
||||
_ = await self._nc.flush()
|
||||
|
||||
# Run publish in background loop
|
||||
future = asyncio.run_coroutine_threadsafe(
|
||||
_publish(),
|
||||
@@ -331,7 +346,7 @@ def create_result(
|
||||
confidence: float,
|
||||
window: int | tuple[int, int],
|
||||
timestamp_ns: int | None = None,
|
||||
) -> dict[str, object]:
|
||||
) -> DemoResult:
|
||||
"""
|
||||
Create a standardized result dictionary.
|
||||
|
||||
@@ -353,7 +368,7 @@ def create_result(
|
||||
|
||||
Returns
|
||||
-------
|
||||
dict[str, object]
|
||||
DemoResult
|
||||
Standardized result dictionary
|
||||
"""
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user