simplify object consolidation

This commit is contained in:
Blake Blackshear 2023-06-10 14:24:09 -05:00
parent c061ff14ee
commit 4e93e8c427

View File

@ -4,7 +4,6 @@ import math
import multiprocessing as mp import multiprocessing as mp
import os import os
import queue import queue
import random
import signal import signal
import subprocess as sp import subprocess as sp
import threading import threading
@ -29,7 +28,6 @@ from frigate.util import (
SharedMemoryFrameManager, SharedMemoryFrameManager,
area, area,
calculate_region, calculate_region,
clipped,
intersection, intersection,
intersection_over_union, intersection_over_union,
listen, listen,
@ -825,13 +823,8 @@ def process_frames(
) )
######### #########
# merge objects, check for clipped objects and look again up to 4 times # merge objects
######### #########
refining = len(regions) > 0
refine_count = 0
while refining and refine_count < 4:
refining = False
# group by name # group by name
detected_object_groups = defaultdict(lambda: []) detected_object_groups = defaultdict(lambda: [])
for detection in detections: for detection in detections:
@ -854,46 +847,15 @@ def process_frames(
confidences = [o[1] for o in group] confidences = [o[1] for o in group]
idxs = cv2.dnn.NMSBoxes(boxes, confidences, 0.5, 0.4) idxs = cv2.dnn.NMSBoxes(boxes, confidences, 0.5, 0.4)
# add objects
for index in idxs: for index in idxs:
index = index if isinstance(index, np.int32) else index[0] index = index if isinstance(index, np.int32) else index[0]
obj = group[index] obj = group[index]
if clipped(obj, frame_shape):
box = obj[2]
# calculate a new region that will hopefully get the entire object
region = calculate_region(
frame_shape,
box[0],
box[1],
box[2],
box[3],
region_min_size,
)
regions.append(region)
selected_objects.extend(
detect(
detect_config,
object_detector,
frame,
model_config,
region,
objects_to_track,
object_filters,
)
)
refining = True
else:
selected_objects.append(obj) selected_objects.append(obj)
# set the detections list to only include top, complete objects # set the detections list to only include top objects
# and new detections
detections = selected_objects detections = selected_objects
if refining:
refine_count += 1
## drop detections that overlap too much ## drop detections that overlap too much
consolidated_detections = [] consolidated_detections = []