mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-12-19 19:06:16 +01:00
Allow zone configs to be frozen
Set the color at construction so the zone config objects can be frozen
This commit is contained in:
parent
84a0827aee
commit
9634ec8e31
@ -289,7 +289,7 @@ ZONE_SCHEMA = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass(frozen=True)
|
||||||
class ZoneConfig:
|
class ZoneConfig:
|
||||||
filters: Dict[str, FilterConfig]
|
filters: Dict[str, FilterConfig]
|
||||||
coordinates: Union[str, List[str]]
|
coordinates: Union[str, List[str]]
|
||||||
@ -297,7 +297,7 @@ class ZoneConfig:
|
|||||||
color: Tuple[int, int, int]
|
color: Tuple[int, int, int]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def build(cls, name, config) -> ZoneConfig:
|
def build(cls, config, color: Tuple[int, int, int]) -> ZoneConfig:
|
||||||
coordinates = config["coordinates"]
|
coordinates = config["coordinates"]
|
||||||
|
|
||||||
if isinstance(coordinates, list):
|
if isinstance(coordinates, list):
|
||||||
@ -317,7 +317,7 @@ class ZoneConfig:
|
|||||||
{name: FilterConfig.build(c) for name, c in config["filters"].items()},
|
{name: FilterConfig.build(c) for name, c in config["filters"].items()},
|
||||||
coordinates,
|
coordinates,
|
||||||
contour,
|
contour,
|
||||||
color=(0, 0, 0),
|
color=color,
|
||||||
)
|
)
|
||||||
|
|
||||||
def to_dict(self) -> Dict[str, Any]:
|
def to_dict(self) -> Dict[str, Any]:
|
||||||
@ -760,8 +760,11 @@ class CameraConfig:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def build(cls, name, config, global_config) -> CameraConfig:
|
def build(cls, name, config, global_config) -> CameraConfig:
|
||||||
zones = {name: ZoneConfig.build(name, z) for name, z in config["zones"].items()}
|
colors = plt.cm.get_cmap("tab10", len(config["zones"]))
|
||||||
cls._set_zone_colors(zones)
|
zones = {
|
||||||
|
name: ZoneConfig.build(z, tuple(round(255 * c) for c in colors(idx)[:3]))
|
||||||
|
for idx, (name, z) in enumerate(config["zones"].items())
|
||||||
|
}
|
||||||
|
|
||||||
frame_shape = config["height"], config["width"]
|
frame_shape = config["height"], config["width"]
|
||||||
|
|
||||||
@ -831,12 +834,6 @@ class CameraConfig:
|
|||||||
|
|
||||||
return [part for part in cmd if part != ""]
|
return [part for part in cmd if part != ""]
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _set_zone_colors(cls, zones: Dict[str, ZoneConfig]) -> None:
|
|
||||||
colors = plt.cm.get_cmap("tab10", len(zones))
|
|
||||||
for i, (name, zone) in enumerate(zones.items()):
|
|
||||||
zone.color = tuple(int(round(255 * c)) for c in colors(i)[:3])
|
|
||||||
|
|
||||||
def to_dict(self) -> Dict[str, Any]:
|
def to_dict(self) -> Dict[str, Any]:
|
||||||
return {
|
return {
|
||||||
"name": self.name,
|
"name": self.name,
|
||||||
|
Loading…
Reference in New Issue
Block a user