mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-03-24 17:18:23 +03:00
fix global object masks
This commit is contained in:
parent
abb03bd554
commit
7d678de445
@ -34,7 +34,7 @@ class MotionMaskConfig(FrigateBaseModel):
|
|||||||
|
|
||||||
@field_serializer("coordinates", when_used="json")
|
@field_serializer("coordinates", when_used="json")
|
||||||
def serialize_coordinates(self, value: Any, info):
|
def serialize_coordinates(self, value: Any, info):
|
||||||
return self.raw_coordinates
|
return self.raw_coordinates if self.raw_coordinates else value
|
||||||
|
|
||||||
@field_serializer("raw_coordinates", when_used="json")
|
@field_serializer("raw_coordinates", when_used="json")
|
||||||
def serialize_raw_coordinates(self, value: Any, info):
|
def serialize_raw_coordinates(self, value: Any, info):
|
||||||
@ -58,16 +58,16 @@ class ObjectMaskConfig(FrigateBaseModel):
|
|||||||
)
|
)
|
||||||
raw_coordinates: Union[str, list[str]] = ""
|
raw_coordinates: Union[str, list[str]] = ""
|
||||||
|
|
||||||
|
@field_serializer("coordinates", when_used="json")
|
||||||
|
def serialize_coordinates(self, value: Any, info):
|
||||||
|
return self.raw_coordinates if self.raw_coordinates else value
|
||||||
|
|
||||||
|
@field_serializer("raw_coordinates", when_used="json")
|
||||||
|
def serialize_raw_coordinates(self, value: Any, info):
|
||||||
|
return None
|
||||||
|
|
||||||
def get_formatted_name(self, mask_id: str) -> str:
|
def get_formatted_name(self, mask_id: str) -> str:
|
||||||
"""Return the friendly name if set, otherwise return a formatted version of the mask ID."""
|
"""Return the friendly name if set, otherwise return a formatted version of the mask ID."""
|
||||||
if self.friendly_name:
|
if self.friendly_name:
|
||||||
return self.friendly_name
|
return self.friendly_name
|
||||||
return mask_id.replace("_", " ").title()
|
return mask_id.replace("_", " ").title()
|
||||||
|
|
||||||
@field_serializer("coordinates", when_used="json")
|
|
||||||
def serialize_coordinates(self, value: Any, info):
|
|
||||||
return self.raw_coordinates
|
|
||||||
|
|
||||||
@field_serializer("raw_coordinates", when_used="json")
|
|
||||||
def serialize_raw_coordinates(self, value: Any, info):
|
|
||||||
return None
|
|
||||||
|
|||||||
@ -788,6 +788,31 @@ class FrigateConfig(FrigateBaseModel):
|
|||||||
for key in object_keys:
|
for key in object_keys:
|
||||||
camera_config.objects.filters[key] = FilterConfig()
|
camera_config.objects.filters[key] = FilterConfig()
|
||||||
|
|
||||||
|
# Process global object masks to set raw_coordinates
|
||||||
|
if camera_config.objects.mask:
|
||||||
|
processed_global_masks = {}
|
||||||
|
for mask_id, mask_config in camera_config.objects.mask.items():
|
||||||
|
if mask_config:
|
||||||
|
coords = mask_config.coordinates
|
||||||
|
relative_coords = get_relative_coordinates(
|
||||||
|
coords, camera_config.frame_shape
|
||||||
|
)
|
||||||
|
# Create a new ObjectMaskConfig with raw_coordinates set
|
||||||
|
from frigate.config.camera.mask import ObjectMaskConfig
|
||||||
|
|
||||||
|
processed_global_masks[mask_id] = ObjectMaskConfig(
|
||||||
|
friendly_name=mask_config.friendly_name,
|
||||||
|
enabled=mask_config.enabled,
|
||||||
|
coordinates=relative_coords if relative_coords else coords,
|
||||||
|
raw_coordinates=relative_coords
|
||||||
|
if relative_coords
|
||||||
|
else coords,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
processed_global_masks[mask_id] = mask_config
|
||||||
|
camera_config.objects.mask = processed_global_masks
|
||||||
|
camera_config.objects.raw_mask = processed_global_masks
|
||||||
|
|
||||||
# Apply global object masks and convert masks to numpy array
|
# Apply global object masks and convert masks to numpy array
|
||||||
for object, filter in camera_config.objects.filters.items():
|
for object, filter in camera_config.objects.filters.items():
|
||||||
# Merge global object masks with per-object filter masks
|
# Merge global object masks with per-object filter masks
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user