mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-10 21:25:24 +03:00
Get motion mask working with relative coordinates
This commit is contained in:
parent
a705e2b6f7
commit
e571853f11
@ -354,6 +354,34 @@ class RuntimeMotionConfig(MotionConfig):
|
||||
frame_shape = config.get("frame_shape", (1, 1))
|
||||
|
||||
mask = config.get("mask", "")
|
||||
|
||||
# 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 mask:
|
||||
if isinstance(mask, list):
|
||||
relative_masks = []
|
||||
for m in mask:
|
||||
points = m.split(",")
|
||||
relative_masks.append(
|
||||
",".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)
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
mask = relative_masks
|
||||
elif isinstance(mask, str):
|
||||
points = mask.split(",")
|
||||
mask = ",".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)
|
||||
]
|
||||
)
|
||||
|
||||
config["raw_mask"] = mask
|
||||
|
||||
if mask:
|
||||
|
||||
@ -739,18 +739,16 @@ def add_mask(mask: str, mask_img: np.ndarray):
|
||||
# masks and zones are saved as relative coordinates
|
||||
# we know if any points are > 1 then it is using the
|
||||
# old native resolution coordinates
|
||||
explicit = any(x > "1.0" for x in points)
|
||||
logger.error(f"received points as {points}")
|
||||
if any(x > "1.0" for x in points):
|
||||
raise Exception("add mask expects relative coordinates only")
|
||||
|
||||
contour = np.array(
|
||||
[
|
||||
(
|
||||
[int(points[i]), int(points[i + 1])]
|
||||
if explicit
|
||||
else [
|
||||
[
|
||||
int(float(points[i]) * mask_img.shape[1]),
|
||||
int(float(points[i + 1]) * mask_img.shape[0]),
|
||||
]
|
||||
)
|
||||
for i in range(0, len(points), 2)
|
||||
]
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user