Add option to have cameras sorted inside the Birdseye stream (#5450)

* Add option to sort cameras inside Birdseye

* Make default order to be sorted alphabetically

* Add docs for sorting cameras

* Update index.md for cameras

* Remove irelevant comments
This commit is contained in:
Alin Balutoiu
2023-04-27 02:29:01 +02:00
committed by GitHub
parent e451f44ced
commit 83006eeb65
4 changed files with 53 additions and 1 deletions

View File

@@ -396,6 +396,7 @@ class BirdseyeConfig(FrigateBaseModel):
# uses BaseModel because some global attributes are not available at the camera level
class BirdseyeCameraConfig(BaseModel):
enabled: bool = Field(default=True, title="Enable birdseye view for camera.")
order: int = Field(default=0, title="Position of the camera in the birdseye view.")
mode: BirdseyeModeEnum = Field(
default=BirdseyeModeEnum.objects, title="Tracking mode for camera."
)

View File

@@ -4,6 +4,7 @@ import logging
import math
import multiprocessing as mp
import os
import operator
import queue
import signal
import subprocess as sp
@@ -292,8 +293,16 @@ class BirdsEyeFrameManager:
# 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:
if layout_dim != self.layout_dim or reset_layout:
if reset_layout:
logger.debug(f"Added new cameras, resetting layout...")
logger.debug(f"Changing layout size from {self.layout_dim} to {layout_dim}")
self.layout_dim = layout_dim
@@ -327,6 +336,20 @@ class BirdsEyeFrameManager:
self.active_cameras = active_cameras
# this also converts added_cameras from a set to a list since we need
# to pop elements in order
added_cameras = sorted(
added_cameras,
# sort cameras by order and by name if the order is the same
key=lambda added_camera: (
self.config.cameras[added_camera].birdseye.order,
added_camera,
),
# we're popping out elements from the end, so this needs to be reverse
# as we want the last element to be the first
reverse=True,
)
# update each position in the layout
for position, camera in enumerate(self.camera_layout, start=0):
# if this camera was removed, replace it or clear it