mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-11 05:35:25 +03:00
Ensure that zone coords are saved as relative
This commit is contained in:
parent
dc22c8d3f1
commit
a705e2b6f7
@ -137,7 +137,8 @@ def stats_history():
|
|||||||
|
|
||||||
@bp.route("/config")
|
@bp.route("/config")
|
||||||
def 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
|
# remove the mqtt password
|
||||||
config["mqtt"].pop("password", None)
|
config["mqtt"].pop("password", None)
|
||||||
@ -155,13 +156,12 @@ def config():
|
|||||||
cmd["cmd"] = clean_camera_user_pass(" ".join(cmd["cmd"]))
|
cmd["cmd"] = clean_camera_user_pass(" ".join(cmd["cmd"]))
|
||||||
|
|
||||||
# ensure that zones are relative
|
# 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()}
|
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"] = (
|
detector_config["model"]["labelmap"] = (
|
||||||
current_app.frigate_config.model.merged_labelmap
|
current_app.frigate_config.model.merged_labelmap
|
||||||
)
|
)
|
||||||
|
|||||||
@ -544,6 +544,9 @@ class ZoneConfig(BaseModel):
|
|||||||
def generate_contour(self, frame_shape: tuple[int, int]):
|
def generate_contour(self, frame_shape: tuple[int, int]):
|
||||||
coordinates = self.coordinates
|
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):
|
if isinstance(coordinates, list):
|
||||||
explicit = any(p.split(",")[0] > "1.0" for p in coordinates)
|
explicit = any(p.split(",")[0] > "1.0" for p in coordinates)
|
||||||
self._contour = np.array(
|
self._contour = np.array(
|
||||||
@ -559,6 +562,14 @@ class ZoneConfig(BaseModel):
|
|||||||
for p in coordinates
|
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):
|
elif isinstance(coordinates, str):
|
||||||
points = coordinates.split(",")
|
points = coordinates.split(",")
|
||||||
explicit = any(p > "1.0" for p in points)
|
explicit = any(p > "1.0" for p in points)
|
||||||
@ -575,6 +586,14 @@ class ZoneConfig(BaseModel):
|
|||||||
for i in range(0, len(points), 2)
|
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:
|
else:
|
||||||
self._contour = np.array([])
|
self._contour = np.array([])
|
||||||
|
|
||||||
|
|||||||
@ -754,5 +754,4 @@ def add_mask(mask: str, mask_img: np.ndarray):
|
|||||||
for i in range(0, len(points), 2)
|
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))
|
cv2.fillPoly(mask_img, pts=[contour], color=(0))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user