mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-08-04 13:47:37 +02:00
output the current frame from each active camera instead of last active
This commit is contained in:
parent
a7ecc2af4b
commit
e0eb247028
@ -117,6 +117,7 @@ class BirdsEyeFrameManager:
|
|||||||
)
|
)
|
||||||
self.cameras[camera] = {
|
self.cameras[camera] = {
|
||||||
"last_active_frame": 0.0,
|
"last_active_frame": 0.0,
|
||||||
|
"current_frame": 0.0,
|
||||||
"layout_frame": 0.0,
|
"layout_frame": 0.0,
|
||||||
"channel_dims": {
|
"channel_dims": {
|
||||||
"y": y,
|
"y": y,
|
||||||
@ -133,6 +134,7 @@ class BirdsEyeFrameManager:
|
|||||||
self.last_output_time = 0.0
|
self.last_output_time = 0.0
|
||||||
|
|
||||||
def clear_frame(self):
|
def clear_frame(self):
|
||||||
|
logger.debug(f"Clearing the birdseye frame")
|
||||||
self.frame[:] = self.blank_frame
|
self.frame[:] = self.blank_frame
|
||||||
|
|
||||||
def copy_to_position(self, position, camera=None, frame_time=None):
|
def copy_to_position(self, position, camera=None, frame_time=None):
|
||||||
@ -165,16 +167,17 @@ class BirdsEyeFrameManager:
|
|||||||
|
|
||||||
def update_frame(self):
|
def update_frame(self):
|
||||||
# determine how many cameras are tracking objects within the last 30 seconds
|
# determine how many cameras are tracking objects within the last 30 seconds
|
||||||
now = datetime.datetime.now().timestamp()
|
|
||||||
|
|
||||||
active_cameras = set(
|
active_cameras = set(
|
||||||
[
|
[
|
||||||
cam
|
cam
|
||||||
for cam, cam_data in self.cameras.items()
|
for cam, cam_data in self.cameras.items()
|
||||||
if now - cam_data["last_active_frame"] < 30
|
if cam_data["last_active_frame"] > 0
|
||||||
|
and cam_data["current_frame"] - cam_data["last_active_frame"] < 30
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
logger.debug(f"Active cameras: {active_cameras}")
|
||||||
|
|
||||||
# if there are no active cameras
|
# if there are no active cameras
|
||||||
if len(active_cameras) == 0:
|
if len(active_cameras) == 0:
|
||||||
# if the layout is already cleared
|
# if the layout is already cleared
|
||||||
@ -188,9 +191,11 @@ class BirdsEyeFrameManager:
|
|||||||
|
|
||||||
# calculate layout dimensions
|
# calculate layout dimensions
|
||||||
layout_dim = math.ceil(math.sqrt(len(active_cameras)))
|
layout_dim = math.ceil(math.sqrt(len(active_cameras)))
|
||||||
|
logger.debug(f"New calculated layout dimensions: {layout_dim}")
|
||||||
|
|
||||||
# reset the layout if it needs to be different
|
# reset the layout if it needs to be different
|
||||||
if layout_dim != self.layout_dim:
|
if layout_dim != self.layout_dim:
|
||||||
|
logger.debug(f"Changing layout size from {self.layout_dim} to {layout_dim}")
|
||||||
self.layout_dim = layout_dim
|
self.layout_dim = layout_dim
|
||||||
|
|
||||||
self.camera_layout = [None] * layout_dim * layout_dim
|
self.camera_layout = [None] * layout_dim * layout_dim
|
||||||
@ -235,11 +240,11 @@ class BirdsEyeFrameManager:
|
|||||||
self.copy_to_position(
|
self.copy_to_position(
|
||||||
position,
|
position,
|
||||||
added_camera,
|
added_camera,
|
||||||
self.cameras[added_camera]["last_active_frame"],
|
self.cameras[added_camera]["current_frame"],
|
||||||
)
|
)
|
||||||
self.cameras[added_camera]["layout_frame"] = self.cameras[
|
self.cameras[added_camera]["layout_frame"] = self.cameras[
|
||||||
added_camera
|
added_camera
|
||||||
]["last_active_frame"]
|
]["current_frame"]
|
||||||
# if removing this camera with no replacement
|
# if removing this camera with no replacement
|
||||||
else:
|
else:
|
||||||
self.camera_layout[position] = None
|
self.camera_layout[position] = None
|
||||||
@ -252,22 +257,22 @@ class BirdsEyeFrameManager:
|
|||||||
self.copy_to_position(
|
self.copy_to_position(
|
||||||
position,
|
position,
|
||||||
added_camera,
|
added_camera,
|
||||||
self.cameras[added_camera]["last_active_frame"],
|
self.cameras[added_camera]["current_frame"],
|
||||||
)
|
)
|
||||||
self.cameras[added_camera]["layout_frame"] = self.cameras[added_camera][
|
self.cameras[added_camera]["layout_frame"] = self.cameras[added_camera][
|
||||||
"last_active_frame"
|
"current_frame"
|
||||||
]
|
]
|
||||||
# if not an empty spot and the camera has a newer frame, copy it
|
# if not an empty spot and the camera has a newer frame, copy it
|
||||||
elif (
|
elif (
|
||||||
not camera is None
|
not camera is None
|
||||||
and self.cameras[camera]["last_active_frame"]
|
and self.cameras[camera]["current_frame"]
|
||||||
!= self.cameras[camera]["layout_frame"]
|
!= self.cameras[camera]["layout_frame"]
|
||||||
):
|
):
|
||||||
self.copy_to_position(
|
self.copy_to_position(
|
||||||
position, camera, self.cameras[camera]["last_active_frame"]
|
position, camera, self.cameras[camera]["current_frame"]
|
||||||
)
|
)
|
||||||
self.cameras[camera]["layout_frame"] = self.cameras[camera][
|
self.cameras[camera]["layout_frame"] = self.cameras[camera][
|
||||||
"last_active_frame"
|
"current_frame"
|
||||||
]
|
]
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@ -275,6 +280,7 @@ class BirdsEyeFrameManager:
|
|||||||
def update(self, camera, object_count, motion_count, frame_time, frame) -> bool:
|
def update(self, camera, object_count, motion_count, frame_time, frame) -> bool:
|
||||||
|
|
||||||
# update the last active frame for the camera
|
# update the last active frame for the camera
|
||||||
|
self.cameras[camera]["current_frame"] = frame_time
|
||||||
if self.camera_active(object_count, motion_count):
|
if self.camera_active(object_count, motion_count):
|
||||||
last_active_frame = self.cameras[camera]["last_active_frame"]
|
last_active_frame = self.cameras[camera]["last_active_frame"]
|
||||||
# cleanup the old frame
|
# cleanup the old frame
|
||||||
|
Loading…
Reference in New Issue
Block a user