Use regions grid for startup scan

This commit is contained in:
Nick Mowen 2023-10-17 14:27:52 -06:00
parent d7b8652b69
commit f05ff552ff
2 changed files with 36 additions and 19 deletions

View File

@ -114,6 +114,8 @@ def get_camera_regions_grid(
std_dev = np.std(cell["sizes"])
mean = np.mean(cell["sizes"])
logger.debug(f"std dev: {std_dev} mean: {mean}")
cell["x"] = x
cell["y"] = y
cell["std_dev"] = std_dev
cell["mean"] = mean
@ -442,3 +444,31 @@ def get_consolidated_object_detections(detected_object_groups):
consolidated_detections.append(sorted_by_area[current_detection_idx])
return consolidated_detections
def get_startup_regions(frame_shape: tuple[int], region_min_size: int, region_grid: list[list[dict[str, any]]]) -> list[list[int]]:
"""Get a list of regions to run on startup."""
# return 8 most popular regions for the camera
all_cells = np.concatenate(region_grid).flat
startup_cells = sorted(all_cells, key=lambda c: len(c["sizes"]), reverse=True)[0:8]
regions = []
for cell in startup_cells:
# rest of the cells are empty
if not cell["sizes"]:
break
x = frame_shape[1] / GRID_SIZE * (0.5 + cell["x"])
y = frame_shape[0] / GRID_SIZE * (0.5 + cell["y"])
size = cell["mean"] * frame_shape[1]
regions.append(calculate_region(
frame_shape,
x - size / 2,
y - size / 2,
x + size / 2,
y + size / 2,
region_min_size,
multiplier=1,
))
return regions

View File

@ -26,7 +26,6 @@ from frigate.util.builtin import EventsPerSecond, get_tomorrow_at_2
from frigate.util.image import (
FrameManager,
SharedMemoryFrameManager,
calculate_region,
draw_box_with_label,
)
from frigate.util.object import (
@ -37,6 +36,7 @@ from frigate.util.object import (
get_cluster_region_from_grid,
get_consolidated_object_detections,
get_min_region_size,
get_startup_regions,
inside_any,
intersects_any,
is_object_filtered,
@ -520,7 +520,7 @@ def process_frames(
fps_tracker = EventsPerSecond()
fps_tracker.start()
startup_scan_counter = 0
startup_scan = True
region_min_size = get_min_region_size(model_config)
@ -626,23 +626,10 @@ def process_frames(
regions += motion_regions
# if starting up, get the next startup scan region
if startup_scan_counter < 9:
ymin = int(frame_shape[0] / 3 * startup_scan_counter / 3)
ymax = int(frame_shape[0] / 3 + ymin)
xmin = int(frame_shape[1] / 3 * startup_scan_counter / 3)
xmax = int(frame_shape[1] / 3 + xmin)
regions.append(
calculate_region(
frame_shape,
xmin,
ymin,
xmax,
ymax,
region_min_size,
multiplier=1.2,
)
)
startup_scan_counter += 1
if startup_scan:
for region in get_startup_regions(frame_shape, region_min_size, region_grid):
regions.append(region)
startup_scan = False
# resize regions and detect
# seed with stationary objects