mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-07 19:55:26 +03:00
Improve logic of birdseye
This commit is contained in:
parent
159fb51518
commit
08e18a2858
@ -433,7 +433,6 @@ class BirdsEyeFrameManager:
|
|||||||
while calculating:
|
while calculating:
|
||||||
if self.stop_event.is_set():
|
if self.stop_event.is_set():
|
||||||
return
|
return
|
||||||
|
|
||||||
layout_candidate = self.calculate_layout(
|
layout_candidate = self.calculate_layout(
|
||||||
active_cameras_to_add,
|
active_cameras_to_add,
|
||||||
coefficient,
|
coefficient,
|
||||||
@ -463,7 +462,7 @@ class BirdsEyeFrameManager:
|
|||||||
def calculate_layout(self, cameras_to_add: list[str], coefficient) -> tuple[any]:
|
def calculate_layout(self, cameras_to_add: list[str], coefficient) -> tuple[any]:
|
||||||
"""Calculate the optimal layout for 2+ cameras."""
|
"""Calculate the optimal layout for 2+ cameras."""
|
||||||
|
|
||||||
def map_layout(row_height: int):
|
def map_layout(camera_layout: list[list[any]], row_height: int):
|
||||||
"""Map the calculated layout."""
|
"""Map the calculated layout."""
|
||||||
candidate_layout = []
|
candidate_layout = []
|
||||||
starting_x = 0
|
starting_x = 0
|
||||||
@ -492,7 +491,7 @@ class BirdsEyeFrameManager:
|
|||||||
x + scaled_width > self.canvas.width
|
x + scaled_width > self.canvas.width
|
||||||
or y + scaled_height > self.canvas.height
|
or y + scaled_height > self.canvas.height
|
||||||
):
|
):
|
||||||
return 0, 0, None
|
return x + scaled_width, y + scaled_height, None
|
||||||
|
|
||||||
final_row.append((cameras[0], (x, y, scaled_width, scaled_height)))
|
final_row.append((cameras[0], (x, y, scaled_width, scaled_height)))
|
||||||
x += scaled_width
|
x += scaled_width
|
||||||
@ -564,10 +563,20 @@ class BirdsEyeFrameManager:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
row_height = int(self.canvas.height / coefficient)
|
row_height = int(self.canvas.height / coefficient)
|
||||||
total_width, total_height, standard_candidate_layout = map_layout(row_height)
|
total_width, total_height, standard_candidate_layout = map_layout(camera_layout, row_height)
|
||||||
|
|
||||||
if not standard_candidate_layout:
|
if not standard_candidate_layout:
|
||||||
return None
|
# if standard layout didn't work
|
||||||
|
# try reducing row_height by the % overflow
|
||||||
|
scale_down_percent = max(
|
||||||
|
total_width / self.canvas.width,
|
||||||
|
total_height / self.canvas.height,
|
||||||
|
)
|
||||||
|
row_height = int(row_height / scale_down_percent)
|
||||||
|
total_width, total_height, standard_candidate_layout = map_layout(camera_layout, row_height)
|
||||||
|
|
||||||
|
if not standard_candidate_layout:
|
||||||
|
return None
|
||||||
|
|
||||||
# layout can't be optimized more
|
# layout can't be optimized more
|
||||||
if total_width / self.canvas.width >= 0.99:
|
if total_width / self.canvas.width >= 0.99:
|
||||||
@ -578,7 +587,7 @@ class BirdsEyeFrameManager:
|
|||||||
1 / (total_height / self.canvas.height),
|
1 / (total_height / self.canvas.height),
|
||||||
)
|
)
|
||||||
row_height = int(row_height * scale_up_percent)
|
row_height = int(row_height * scale_up_percent)
|
||||||
_, _, scaled_layout = map_layout(row_height)
|
_, _, scaled_layout = map_layout(camera_layout, row_height)
|
||||||
|
|
||||||
if scaled_layout:
|
if scaled_layout:
|
||||||
return scaled_layout
|
return scaled_layout
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user