mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-07 03:35:26 +03:00
Use regions grid for startup scan
This commit is contained in:
parent
d7b8652b69
commit
f05ff552ff
@ -114,6 +114,8 @@ def get_camera_regions_grid(
|
|||||||
std_dev = np.std(cell["sizes"])
|
std_dev = np.std(cell["sizes"])
|
||||||
mean = np.mean(cell["sizes"])
|
mean = np.mean(cell["sizes"])
|
||||||
logger.debug(f"std dev: {std_dev} mean: {mean}")
|
logger.debug(f"std dev: {std_dev} mean: {mean}")
|
||||||
|
cell["x"] = x
|
||||||
|
cell["y"] = y
|
||||||
cell["std_dev"] = std_dev
|
cell["std_dev"] = std_dev
|
||||||
cell["mean"] = mean
|
cell["mean"] = mean
|
||||||
|
|
||||||
@ -442,3 +444,31 @@ def get_consolidated_object_detections(detected_object_groups):
|
|||||||
consolidated_detections.append(sorted_by_area[current_detection_idx])
|
consolidated_detections.append(sorted_by_area[current_detection_idx])
|
||||||
|
|
||||||
return consolidated_detections
|
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
|
||||||
|
|||||||
@ -26,7 +26,6 @@ from frigate.util.builtin import EventsPerSecond, get_tomorrow_at_2
|
|||||||
from frigate.util.image import (
|
from frigate.util.image import (
|
||||||
FrameManager,
|
FrameManager,
|
||||||
SharedMemoryFrameManager,
|
SharedMemoryFrameManager,
|
||||||
calculate_region,
|
|
||||||
draw_box_with_label,
|
draw_box_with_label,
|
||||||
)
|
)
|
||||||
from frigate.util.object import (
|
from frigate.util.object import (
|
||||||
@ -37,6 +36,7 @@ from frigate.util.object import (
|
|||||||
get_cluster_region_from_grid,
|
get_cluster_region_from_grid,
|
||||||
get_consolidated_object_detections,
|
get_consolidated_object_detections,
|
||||||
get_min_region_size,
|
get_min_region_size,
|
||||||
|
get_startup_regions,
|
||||||
inside_any,
|
inside_any,
|
||||||
intersects_any,
|
intersects_any,
|
||||||
is_object_filtered,
|
is_object_filtered,
|
||||||
@ -520,7 +520,7 @@ def process_frames(
|
|||||||
fps_tracker = EventsPerSecond()
|
fps_tracker = EventsPerSecond()
|
||||||
fps_tracker.start()
|
fps_tracker.start()
|
||||||
|
|
||||||
startup_scan_counter = 0
|
startup_scan = True
|
||||||
|
|
||||||
region_min_size = get_min_region_size(model_config)
|
region_min_size = get_min_region_size(model_config)
|
||||||
|
|
||||||
@ -626,23 +626,10 @@ def process_frames(
|
|||||||
regions += motion_regions
|
regions += motion_regions
|
||||||
|
|
||||||
# if starting up, get the next startup scan region
|
# if starting up, get the next startup scan region
|
||||||
if startup_scan_counter < 9:
|
if startup_scan:
|
||||||
ymin = int(frame_shape[0] / 3 * startup_scan_counter / 3)
|
for region in get_startup_regions(frame_shape, region_min_size, region_grid):
|
||||||
ymax = int(frame_shape[0] / 3 + ymin)
|
regions.append(region)
|
||||||
xmin = int(frame_shape[1] / 3 * startup_scan_counter / 3)
|
startup_scan = False
|
||||||
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
|
|
||||||
|
|
||||||
# resize regions and detect
|
# resize regions and detect
|
||||||
# seed with stationary objects
|
# seed with stationary objects
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user