53 lines
1014 B
Python
53 lines
1014 B
Python
"""Privacy-preserving vision ports and observations."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Protocol
|
|
|
|
from yovision_brain.decode import DecodedFrame
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class DetectorMetadata:
|
|
name: str
|
|
version: str
|
|
source: str
|
|
license: str
|
|
weights: str
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class BoundingBox:
|
|
left: int
|
|
top: int
|
|
right: int
|
|
bottom: int
|
|
|
|
@property
|
|
def area(self) -> int:
|
|
return max(0, self.right - self.left) * max(0, self.bottom - self.top)
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class Detection:
|
|
box: BoundingBox
|
|
category: str
|
|
confidence: float
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class TrackedObject:
|
|
track_id: str
|
|
box: BoundingBox
|
|
category: str
|
|
confidence: float
|
|
frame_sequence: int
|
|
timestamp_ns: int
|
|
|
|
|
|
class Detector(Protocol):
|
|
metadata: DetectorMetadata
|
|
|
|
def detect(self, frame: DecodedFrame) -> tuple[Detection, ...]: ...
|