consolidate regions

This commit is contained in:
Blake Blackshear 2021-11-04 11:57:26 -05:00
parent 08ddfc100f
commit 258215a3ae

View File

@ -11,7 +11,7 @@ from collections import defaultdict
from typing import Dict, List from typing import Dict, List
import numpy as np import numpy as np
from cv2 import cv2 from cv2 import cv2, reduce
from setproctitle import setproctitle from setproctitle import setproctitle
from frigate.config import CameraConfig, DetectConfig from frigate.config import CameraConfig, DetectConfig
@ -389,13 +389,13 @@ def box_overlaps(b1, b2):
return True return True
def reduce_boxes(boxes): def reduce_boxes(boxes, iou_threshold=0.0):
clusters = [] clusters = []
for box in boxes: for box in boxes:
matched = 0 matched = 0
for cluster in clusters: for cluster in clusters:
if box_overlaps(box, cluster): if intersection_over_union(box, cluster) > iou_threshold:
matched = 1 matched = 1
cluster[0] = min(cluster[0], box[0]) cluster[0] = min(cluster[0], box[0])
cluster[1] = min(cluster[1], box[1]) cluster[1] = min(cluster[1], box[1])
@ -535,6 +535,12 @@ def process_frames(
for a in combined_boxes for a in combined_boxes
] ]
# consolidate regions with heavy overlap
regions = [
calculate_region(frame_shape, a[0], a[1], a[2], a[3], 1.0)
for a in reduce_boxes(regions, 0.4)
]
# resize regions and detect # resize regions and detect
# seed with stationary objects # seed with stationary objects
detections = [ detections = [