mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-11 05:35:25 +03:00
Rewrite object mask to use relative coordinates as well
This commit is contained in:
parent
e571853f11
commit
d78614705c
@ -434,7 +434,7 @@ def motion_activity():
|
|||||||
.fillna(0.0)
|
.fillna(0.0)
|
||||||
.to_frame()
|
.to_frame()
|
||||||
)
|
)
|
||||||
cameras = df["camera"].resample(f"{scale}S").agg(lambda x: ",".join(set(x)))
|
cameras = df["camera"].resample(f"{scale}s").agg(lambda x: ",".join(set(x)))
|
||||||
df = motion.join(cameras)
|
df = motion.join(cameras)
|
||||||
|
|
||||||
length = df.shape[0]
|
length = df.shape[0]
|
||||||
|
|||||||
@ -366,7 +366,7 @@ class RuntimeMotionConfig(MotionConfig):
|
|||||||
relative_masks.append(
|
relative_masks.append(
|
||||||
",".join(
|
",".join(
|
||||||
[
|
[
|
||||||
f"{round(int(points[i]) / frame_shape[1], 2)},{round(int(points[i + 1]) / frame_shape[0], 2)}"
|
f"{round(int(points[i]) / frame_shape[1], 3)},{round(int(points[i + 1]) / frame_shape[0], 3)}"
|
||||||
for i in range(0, len(points), 2)
|
for i in range(0, len(points), 2)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@ -377,7 +377,7 @@ class RuntimeMotionConfig(MotionConfig):
|
|||||||
points = mask.split(",")
|
points = mask.split(",")
|
||||||
mask = ",".join(
|
mask = ",".join(
|
||||||
[
|
[
|
||||||
f"{round(int(points[i]) / frame_shape[1], 2)},{round(int(points[i + 1]) / frame_shape[0], 2)}"
|
f"{round(int(points[i]) / frame_shape[1], 3)},{round(int(points[i + 1]) / frame_shape[0], 3)}"
|
||||||
for i in range(0, len(points), 2)
|
for i in range(0, len(points), 2)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@ -512,11 +512,40 @@ class RuntimeFilterConfig(FilterConfig):
|
|||||||
raw_mask: Optional[Union[str, List[str]]] = None
|
raw_mask: Optional[Union[str, List[str]]] = None
|
||||||
|
|
||||||
def __init__(self, **config):
|
def __init__(self, **config):
|
||||||
|
frame_shape = config.get("frame_shape", (1, 1))
|
||||||
mask = config.get("mask")
|
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], 3)},{round(int(points[i + 1]) / frame_shape[0], 3)}"
|
||||||
|
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], 3)},{round(int(points[i + 1]) / frame_shape[0], 3)}"
|
||||||
|
for i in range(0, len(points), 2)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
config["raw_mask"] = mask
|
config["raw_mask"] = mask
|
||||||
|
|
||||||
if mask is not None:
|
if mask is not None:
|
||||||
config["mask"] = create_mask(config.get("frame_shape", (1, 1)), mask)
|
config["mask"] = create_mask(frame_shape, mask)
|
||||||
|
|
||||||
super().__init__(**config)
|
super().__init__(**config)
|
||||||
|
|
||||||
@ -594,7 +623,7 @@ class ZoneConfig(BaseModel):
|
|||||||
if explicit:
|
if explicit:
|
||||||
self.coordinates = ",".join(
|
self.coordinates = ",".join(
|
||||||
[
|
[
|
||||||
f'{round(int(p.split(",")[0]) / frame_shape[1], 2)},{round(int(p.split(",")[1]) / frame_shape[0], 2)}'
|
f'{round(int(p.split(",")[0]) / frame_shape[1], 3)},{round(int(p.split(",")[1]) / frame_shape[0], 3)}'
|
||||||
for p in coordinates
|
for p in coordinates
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@ -618,7 +647,7 @@ class ZoneConfig(BaseModel):
|
|||||||
if explicit:
|
if explicit:
|
||||||
self.coordinates = ",".join(
|
self.coordinates = ",".join(
|
||||||
[
|
[
|
||||||
f"{round(int(points[i]) / frame_shape[1], 2)},{round(int(points[i + 1]) / frame_shape[0], 2)}"
|
f"{round(int(points[i]) / frame_shape[1], 3)},{round(int(points[i + 1]) / frame_shape[0], 3)}"
|
||||||
for i in range(0, len(points), 2)
|
for i in range(0, len(points), 2)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
@ -739,7 +739,6 @@ def add_mask(mask: str, mask_img: np.ndarray):
|
|||||||
# masks and zones are saved as relative coordinates
|
# masks and zones are saved as relative coordinates
|
||||||
# we know if any points are > 1 then it is using the
|
# we know if any points are > 1 then it is using the
|
||||||
# old native resolution coordinates
|
# old native resolution coordinates
|
||||||
logger.error(f"received points as {points}")
|
|
||||||
if any(x > "1.0" for x in points):
|
if any(x > "1.0" for x in points):
|
||||||
raise Exception("add mask expects relative coordinates only")
|
raise Exception("add mask expects relative coordinates only")
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user