diff --git a/frigate/config/camera/mask.py b/frigate/config/camera/mask.py index caba8aa6e..939957578 100644 --- a/frigate/config/camera/mask.py +++ b/frigate/config/camera/mask.py @@ -34,7 +34,7 @@ class MotionMaskConfig(FrigateBaseModel): @field_serializer("coordinates", when_used="json") 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") def serialize_raw_coordinates(self, value: Any, info): @@ -58,16 +58,16 @@ class ObjectMaskConfig(FrigateBaseModel): ) 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: """Return the friendly name if set, otherwise return a formatted version of the mask ID.""" if self.friendly_name: return self.friendly_name 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 diff --git a/frigate/config/config.py b/frigate/config/config.py index 1bd61fbfd..5bc2518d5 100644 --- a/frigate/config/config.py +++ b/frigate/config/config.py @@ -788,6 +788,31 @@ class FrigateConfig(FrigateBaseModel): for key in object_keys: 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 for object, filter in camera_config.objects.filters.items(): # Merge global object masks with per-object filter masks