mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-05 10:45:21 +03:00
Optimally handle cameras that don't match the canvas aspect ratio
This commit is contained in:
parent
ff18c5e5a3
commit
0dee3f29ad
@ -211,7 +211,7 @@ class BirdsEyeFrameManager:
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
self.cameras[camera] = {
|
self.cameras[camera] = {
|
||||||
"dimensions": (settings.detect.width, settings.detect.height),
|
"dimensions": [settings.detect.width, settings.detect.height],
|
||||||
"last_active_frame": 0.0,
|
"last_active_frame": 0.0,
|
||||||
"current_frame": 0.0,
|
"current_frame": 0.0,
|
||||||
"layout_frame": 0.0,
|
"layout_frame": 0.0,
|
||||||
@ -276,12 +276,21 @@ class BirdsEyeFrameManager:
|
|||||||
"""Calculate the optimal layout for cameras."""
|
"""Calculate the optimal layout for cameras."""
|
||||||
camera_layout: list[list[any]] = []
|
camera_layout: list[list[any]] = []
|
||||||
camera_layout.append([])
|
camera_layout.append([])
|
||||||
|
canvas_aspect = canvas[0] / canvas[1]
|
||||||
x = 0
|
x = 0
|
||||||
y = 0
|
y = 0
|
||||||
y_i = 0
|
y_i = 0
|
||||||
max_height = 0
|
max_height = 0
|
||||||
for camera in cameras_to_add:
|
for camera in cameras_to_add:
|
||||||
if (x + self.cameras[camera]["settings"][0] * coefficient) <= canvas[0]:
|
camera_dims = self.cameras[camera]["dimensions"]
|
||||||
|
camera_aspect = camera_dims[0] / camera_dims[1]
|
||||||
|
|
||||||
|
# if the camera aspect ratio is less than canvas aspect ratio, it needs to be scaled down to fit
|
||||||
|
if camera_aspect < canvas_aspect:
|
||||||
|
camera_dims[0] *= camera_aspect / canvas_aspect
|
||||||
|
camera_dims[1] *= camera_aspect / canvas_aspect
|
||||||
|
|
||||||
|
if (x + camera_dims[0] * coefficient) <= canvas[0]:
|
||||||
# insert if camera can fit on current row
|
# insert if camera can fit on current row
|
||||||
camera_layout[y_i].append(
|
camera_layout[y_i].append(
|
||||||
(
|
(
|
||||||
@ -289,15 +298,15 @@ class BirdsEyeFrameManager:
|
|||||||
(
|
(
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
int(self.cameras[camera]["settings"][0] * coefficient),
|
int(camera_dims[0] * coefficient),
|
||||||
int(self.cameras[camera]["settings"][1] * coefficient),
|
int(camera_dims[1] * coefficient),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
x += int(self.cameras[camera]["settings"][0] * coefficient)
|
x += int(camera_dims[0] * coefficient)
|
||||||
max_height = max(
|
max_height = max(
|
||||||
max_height,
|
max_height,
|
||||||
int(self.cameras[camera]["settings"][1] * coefficient),
|
int(camera_dims[1] * coefficient),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# move on to the next row and insert
|
# move on to the next row and insert
|
||||||
@ -311,12 +320,12 @@ class BirdsEyeFrameManager:
|
|||||||
(
|
(
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
int(self.cameras[camera]["settings"][0] * coefficient),
|
int(camera_dims[0] * coefficient),
|
||||||
int(self.cameras[camera]["settings"][1] * coefficient),
|
int(camera_dims[1] * coefficient),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
x += int(self.cameras[camera]["settings"][0] * coefficient)
|
x += int(camera_dims[0] * coefficient)
|
||||||
|
|
||||||
return (camera_layout, y + max_height)
|
return (camera_layout, y + max_height)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user