Spaces:
Sleeping
Sleeping
File size: 740 Bytes
a49c70b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | """Segment data model for detected objects."""
from __future__ import annotations
from dataclasses import dataclass, field
import numpy as np
@dataclass
class Segment:
"""A detected object segment in an image."""
id: int
mask: np.ndarray # (H, W) boolean mask
bbox: list[int] # [x1, y1, x2, y2]
area: int
confidence: float = 0.0
saliency_score: float = 0.0
@property
def width(self) -> int:
return self.bbox[2] - self.bbox[0]
@property
def height(self) -> int:
return self.bbox[3] - self.bbox[1]
@property
def center(self) -> tuple[int, int]:
cx = (self.bbox[0] + self.bbox[2]) // 2
cy = (self.bbox[1] + self.bbox[3]) // 2
return cx, cy
|