diff --git a/frigate/api/app.py b/frigate/api/app.py index c9b71d019..ea8ad4bdd 100644 --- a/frigate/api/app.py +++ b/frigate/api/app.py @@ -137,7 +137,8 @@ def stats_history(): @bp.route("/config") def config(): - config = current_app.frigate_config.model_dump(mode="json", exclude_none=True) + config_obj: FrigateConfig = current_app.frigate_config + config: dict[str, dict[str, any]] = config_obj.model_dump(mode="json", exclude_none=True) # remove the mqtt password config["mqtt"].pop("password", None) @@ -155,13 +156,12 @@ def config(): cmd["cmd"] = clean_camera_user_pass(" ".join(cmd["cmd"])) # ensure that zones are relative - for zone in camera_dict.get("zones", []): - - + for zone_name, zone in config_obj.cameras[camera_name].zones.items(): + camera_dict["zones"][zone_name]["color"] = zone.color config["plus"] = {"enabled": current_app.plus_api.is_active()} - for detector, detector_config in config["detectors"].items(): + for detector_config in config["detectors"].values(): detector_config["model"]["labelmap"] = ( current_app.frigate_config.model.merged_labelmap ) diff --git a/frigate/config.py b/frigate/config.py index 7ca8726dc..4907c1919 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -544,6 +544,9 @@ class ZoneConfig(BaseModel): def generate_contour(self, frame_shape: tuple[int, int]): coordinates = self.coordinates + # masks and zones are saved as relative coordinates + # we know if any points are > 1 then it is using the + # old native resolution coordinates if isinstance(coordinates, list): explicit = any(p.split(",")[0] > "1.0" for p in coordinates) self._contour = np.array( @@ -559,6 +562,14 @@ class ZoneConfig(BaseModel): for p in coordinates ] ) + + if explicit: + self.coordinates = ",".join( + [ + f'{round(int(p.split(",")[0]) / frame_shape[1], 2)},{round(int(p.split(",")[1]) / frame_shape[0], 2)}' + for p in coordinates + ] + ) elif isinstance(coordinates, str): points = coordinates.split(",") explicit = any(p > "1.0" for p in points) @@ -575,6 +586,14 @@ class ZoneConfig(BaseModel): for i in range(0, len(points), 2) ] ) + + if explicit: + self.coordinates = ",".join( + [ + f"{round(int(points[i]) / frame_shape[1], 2)},{round(int(points[i + 1]) / frame_shape[0], 2)}" + for i in range(0, len(points), 2) + ] + ) else: self._contour = np.array([]) diff --git a/frigate/util/image.py b/frigate/util/image.py index f4207c98e..45cdfec79 100644 --- a/frigate/util/image.py +++ b/frigate/util/image.py @@ -754,5 +754,4 @@ def add_mask(mask: str, mask_img: np.ndarray): for i in range(0, len(points), 2) ] ) - logger.error(f"the mask is {contour} from {mask} and explicit {explicit}") cv2.fillPoly(mask_img, pts=[contour], color=(0))