From ff18c5e5a3b928f55f55d72e19b7b0acd679aad8 Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Wed, 7 Jun 2023 10:18:34 -0600 Subject: [PATCH] Remove logs --- frigate/output.py | 124 ++++++++++++++++++---------------------------- 1 file changed, 48 insertions(+), 76 deletions(-) diff --git a/frigate/output.py b/frigate/output.py index f23b96efd..739612493 100644 --- a/frigate/output.py +++ b/frigate/output.py @@ -7,7 +7,6 @@ import os import queue import signal import subprocess as sp -import sys import threading import traceback from wsgiref.simple_server import make_server @@ -212,6 +211,7 @@ class BirdsEyeFrameManager: ), ) self.cameras[camera] = { + "dimensions": (settings.detect.width, settings.detect.height), "last_active_frame": 0.0, "current_frame": 0.0, "layout_frame": 0.0, @@ -226,7 +226,6 @@ class BirdsEyeFrameManager: self.camera_layout = [] self.active_cameras = set() - self.layout_dim = 0 self.last_output_time = 0.0 def clear_frame(self): @@ -250,8 +249,6 @@ class BirdsEyeFrameManager: return channel_dims = self.cameras[camera]["channel_dims"] - logger.error(f"Copy to yuv {position}") - copy_yuv_to_position( self.frame, [position[1], position[0]], @@ -271,9 +268,12 @@ class BirdsEyeFrameManager: return True def update_frame(self): + """Update to a new frame for birdseye.""" + def calculate_layout( canvas, cameras_to_add: list[str], coefficient ) -> tuple[any]: + """Calculate the optimal layout for cameras.""" camera_layout: list[list[any]] = [] camera_layout.append([]) x = 0 @@ -281,18 +281,24 @@ class BirdsEyeFrameManager: y_i = 0 max_height = 0 for camera in cameras_to_add: - detect_config = self.config.cameras[camera].detect - - if (x + self.config.cameras[camera].detect.width * coefficient) <= canvas[0]: + if (x + self.cameras[camera]["settings"][0] * coefficient) <= canvas[0]: # insert if camera can fit on current row camera_layout[y_i].append( ( camera, - (x, y, int(detect_config.width * coefficient), int(detect_config.height * coefficient)), + ( + x, + y, + int(self.cameras[camera]["settings"][0] * coefficient), + int(self.cameras[camera]["settings"][1] * coefficient), + ), ) ) - x += int(detect_config.width * coefficient) - max_height = max(max_height, int(detect_config.height * coefficient)) + x += int(self.cameras[camera]["settings"][0] * coefficient) + max_height = max( + max_height, + int(self.cameras[camera]["settings"][1] * coefficient), + ) else: # move on to the next row and insert y += max_height @@ -302,12 +308,16 @@ class BirdsEyeFrameManager: camera_layout[y_i].append( ( camera, - (x, y, int(detect_config.width * coefficient), int(detect_config.height * coefficient)), + ( + x, + y, + int(self.cameras[camera]["settings"][0] * coefficient), + int(self.cameras[camera]["settings"][1] * coefficient), + ), ) ) - x += int(detect_config.width * coefficient) + x += int(self.cameras[camera]["settings"][0] * coefficient) - logger.error(f"Calc total height {y + max_height}") return (camera_layout, y + max_height) # determine how many cameras are tracking objects within the last 30 seconds @@ -328,86 +338,48 @@ class BirdsEyeFrameManager: # if the layout needs to be cleared else: self.camera_layout = [] - self.layout_dim = 0 + self.active_cameras = set() self.clear_frame() return True - # calculate layout dimensions - layout_dim = math.ceil(math.sqrt(len(active_cameras))) - # check if we need to reset the layout because there are new cameras to add reset_layout = ( True if len(active_cameras.difference(self.active_cameras)) > 0 else False ) # reset the layout if it needs to be different - if layout_dim != self.layout_dim or reset_layout: - if reset_layout: - logger.debug("Added new cameras, resetting layout...") - - logger.debug(f"Changing layout size from {self.layout_dim} to {layout_dim}") - self.layout_dim = layout_dim - - self.camera_layout = [None] * layout_dim * layout_dim - - # calculate resolution of each position in the layout - self.layout_frame_shape = ( - self.frame_shape[0] // layout_dim, # height - self.frame_shape[1] // layout_dim, # width - ) - + if reset_layout: + logger.debug("Added new cameras, resetting layout...") self.clear_frame() + self.active_cameras = active_cameras - for cam_data in self.cameras.values(): - cam_data["layout_frame"] = 0.0 - - self.active_cameras = set() - - self.layout_offsets = [] - - # calculate the x and y offset for each position in the layout - for position in range(0, len(self.camera_layout)): - y_offset = self.layout_frame_shape[0] * math.floor( - position / self.layout_dim - ) - x_offset = self.layout_frame_shape[1] * (position % self.layout_dim) - self.layout_offsets.append((y_offset, x_offset)) - - removed_cameras = self.active_cameras.difference(active_cameras) - added_cameras = active_cameras.difference(self.active_cameras) - - self.active_cameras = active_cameras - - # this also converts added_cameras from a set to a list since we need - # to pop elements in order - active_cameras_to_add = sorted( - active_cameras, - # sort cameras by order and by name if the order is the same - key=lambda active_camera: ( - self.config.cameras[active_camera].birdseye.order, - active_camera, - ), - ) - - canvas_width = self.config.birdseye.width - canvas_height = self.config.birdseye.height - coefficient = 1.0 - - while True: - layout_candidate, total_height = calculate_layout( - (canvas_width, canvas_height), active_cameras_to_add, coefficient + # this also converts added_cameras from a set to a list since we need + # to pop elements in order + active_cameras_to_add = sorted( + active_cameras, + # sort cameras by order and by name if the order is the same + key=lambda active_camera: ( + self.config.cameras[active_camera].birdseye.order, + active_camera, + ), ) - logger.error(f"With a coefficient of {coefficient} the total height is {total_height}") + canvas_width = self.config.birdseye.width + canvas_height = self.config.birdseye.height + coefficient = 1.0 - if total_height <= canvas_height: - break + # decrease scaling coefficient until height of all cameras can fit into the birdseye canvas + while True: + layout_candidate, total_height = calculate_layout( + (canvas_width, canvas_height), active_cameras_to_add, coefficient + ) - coefficient -= 0.1 + if total_height <= canvas_height: + break - self.camera_layout = layout_candidate + coefficient -= 0.1 - logger.error(f"The final layout is {self.camera_layout}") + self.camera_layout = layout_candidate for row in self.camera_layout: for position in row: