mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-06-21 03:41:55 +03:00
Merge ae2a9c5be4 into 5003ab895c
This commit is contained in:
commit
ffe8820f8a
@ -82,6 +82,24 @@ class TestRegion(unittest.TestCase):
|
|||||||
|
|
||||||
assert len(cluster_candidates) == 2
|
assert len(cluster_candidates) == 2
|
||||||
|
|
||||||
|
def test_cluster_candidates_partition_boxes(self):
|
||||||
|
# every box index must appear in exactly one cluster (no box used twice,
|
||||||
|
# none dropped) - the invariant the used-box tracking enforces
|
||||||
|
boxes = [
|
||||||
|
(100, 100, 200, 200),
|
||||||
|
(202, 150, 252, 200),
|
||||||
|
(210, 160, 260, 210),
|
||||||
|
(900, 900, 950, 950),
|
||||||
|
(905, 905, 955, 955),
|
||||||
|
]
|
||||||
|
|
||||||
|
cluster_candidates = get_cluster_candidates(
|
||||||
|
self.frame_shape, self.min_region_size, boxes
|
||||||
|
)
|
||||||
|
|
||||||
|
assigned = [idx for cluster in cluster_candidates for idx in cluster]
|
||||||
|
self.assertEqual(sorted(assigned), list(range(len(boxes))))
|
||||||
|
|
||||||
def test_transliterate_to_latin(self):
|
def test_transliterate_to_latin(self):
|
||||||
self.assertEqual(transliterate_to_latin("frégate"), "fregate")
|
self.assertEqual(transliterate_to_latin("frégate"), "fregate")
|
||||||
self.assertEqual(transliterate_to_latin("utilité"), "utilite")
|
self.assertEqual(transliterate_to_latin("utilité"), "utilite")
|
||||||
|
|||||||
@ -401,13 +401,13 @@ def get_cluster_candidates(frame_shape, min_region, boxes):
|
|||||||
# determined by the max_region size minus half the box + 20%
|
# determined by the max_region size minus half the box + 20%
|
||||||
# TODO: see if we can do this with numpy
|
# TODO: see if we can do this with numpy
|
||||||
cluster_candidates = []
|
cluster_candidates = []
|
||||||
used_boxes = []
|
used_boxes = set()
|
||||||
# loop over each box
|
# loop over each box
|
||||||
for current_index, b in enumerate(boxes):
|
for current_index, b in enumerate(boxes):
|
||||||
if current_index in used_boxes:
|
if current_index in used_boxes:
|
||||||
continue
|
continue
|
||||||
cluster = [current_index]
|
cluster = [current_index]
|
||||||
used_boxes.append(current_index)
|
used_boxes.add(current_index)
|
||||||
cluster_boundary = get_cluster_boundary(b, min_region)
|
cluster_boundary = get_cluster_boundary(b, min_region)
|
||||||
# find all other boxes that fit inside the boundary
|
# find all other boxes that fit inside the boundary
|
||||||
for compare_index, compare_box in enumerate(boxes):
|
for compare_index, compare_box in enumerate(boxes):
|
||||||
@ -436,7 +436,7 @@ def get_cluster_candidates(frame_shape, min_region, boxes):
|
|||||||
|
|
||||||
if should_cluster:
|
if should_cluster:
|
||||||
cluster.append(compare_index)
|
cluster.append(compare_index)
|
||||||
used_boxes.append(compare_index)
|
used_boxes.add(compare_index)
|
||||||
cluster_candidates.append(cluster)
|
cluster_candidates.append(cluster)
|
||||||
|
|
||||||
# return the unique clusters only
|
# return the unique clusters only
|
||||||
@ -558,6 +558,7 @@ def reduce_detections(
|
|||||||
current_detection = sorted_by_area[current_detection_idx]
|
current_detection = sorted_by_area[current_detection_idx]
|
||||||
current_label = current_detection[0]
|
current_label = current_detection[0]
|
||||||
current_box = current_detection[2]
|
current_box = current_detection[2]
|
||||||
|
current_area = area(current_box)
|
||||||
overlap = 0
|
overlap = 0
|
||||||
for to_check_idx in range(
|
for to_check_idx in range(
|
||||||
min(current_detection_idx + 1, len(sorted_by_area)),
|
min(current_detection_idx + 1, len(sorted_by_area)),
|
||||||
@ -568,14 +569,14 @@ def reduce_detections(
|
|||||||
# if area of current detection / area of check < 5% they should not be compared
|
# if area of current detection / area of check < 5% they should not be compared
|
||||||
# this covers cases where a large car parked in a driveway doesn't block detections
|
# this covers cases where a large car parked in a driveway doesn't block detections
|
||||||
# of cars in the street behind it
|
# of cars in the street behind it
|
||||||
if area(current_box) / area(to_check) < 0.05:
|
if current_area / area(to_check) < 0.05:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
intersect_box = intersection(current_box, to_check)
|
intersect_box = intersection(current_box, to_check)
|
||||||
# if % of smaller detection is inside of another detection, consolidate
|
# if % of smaller detection is inside of another detection, consolidate
|
||||||
if intersect_box is not None and area(intersect_box) / area(
|
if intersect_box is not None and area(
|
||||||
current_box
|
intersect_box
|
||||||
) > LABEL_CONSOLIDATION_MAP.get(
|
) / current_area > LABEL_CONSOLIDATION_MAP.get(
|
||||||
current_label, LABEL_CONSOLIDATION_DEFAULT
|
current_label, LABEL_CONSOLIDATION_DEFAULT
|
||||||
):
|
):
|
||||||
overlap = 1
|
overlap = 1
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user