mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-08 20:25:26 +03:00
Use average of boxes instead of average of iou
This commit is contained in:
parent
f61b06fd61
commit
e82befb53e
@ -17,6 +17,7 @@ from frigate.ptz.autotrack import PtzMotionEstimator
|
||||
from frigate.track import ObjectTracker
|
||||
from frigate.types import PTZMetricsTypes
|
||||
from frigate.util.image import intersection_over_union
|
||||
from frigate.util.object import average_boxes
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -132,7 +133,7 @@ class NorfairTracker(ObjectTracker):
|
||||
"xmax": self.detect_config.width,
|
||||
"ymax": self.detect_config.height,
|
||||
}
|
||||
self.stationary_iou[id] = []
|
||||
self.stationary_box_history[id] = []
|
||||
|
||||
def deregister(self, id, track_id):
|
||||
del self.tracked_objects[id]
|
||||
@ -146,13 +147,6 @@ class NorfairTracker(ObjectTracker):
|
||||
# returns False if the object has moved outside its previous position
|
||||
def update_position(self, id: str, box: list[int, int, int, int]):
|
||||
position = self.positions[id]
|
||||
position_box = (
|
||||
position["xmin"],
|
||||
position["ymin"],
|
||||
position["xmax"],
|
||||
position["ymax"],
|
||||
)
|
||||
|
||||
self.stationary_box_history[id].append(box)
|
||||
|
||||
if len(self.stationary_box_history[id]) > MAX_STATIONARY_HISTORY:
|
||||
@ -161,7 +155,9 @@ class NorfairTracker(ObjectTracker):
|
||||
]
|
||||
|
||||
# TODO calculate mean of boxes
|
||||
avg_iou = np.mean(self.stationary_iou[id])
|
||||
avg_iou = intersection_over_union(
|
||||
box, average_boxes(self.stationary_box_history[id])
|
||||
)
|
||||
|
||||
xmin, ymin, xmax, ymax = box
|
||||
|
||||
@ -234,7 +230,7 @@ class NorfairTracker(ObjectTracker):
|
||||
):
|
||||
self.tracked_objects[id]["position_changes"] += 1
|
||||
self.tracked_objects[id]["motionless_count"] = 0
|
||||
self.stationary_iou[id] = []
|
||||
self.stationary_box_history[id] = []
|
||||
|
||||
self.tracked_objects[id].update(obj)
|
||||
|
||||
|
||||
@ -323,6 +323,22 @@ def reduce_boxes(boxes, iou_threshold=0.0):
|
||||
return [tuple(c) for c in clusters]
|
||||
|
||||
|
||||
def average_boxes(boxes: list[list[int, int, int, int]]) -> list[int, int, int, int]:
|
||||
"""Return a box that is the average of a list of boxes."""
|
||||
x_mins = []
|
||||
y_mins = []
|
||||
x_max = []
|
||||
y_max = []
|
||||
|
||||
for box in boxes:
|
||||
x_mins.append(box[0])
|
||||
y_mins.append(box[1])
|
||||
x_max.append(box[2])
|
||||
y_max.append(box[3])
|
||||
|
||||
return [np.mean(x_mins), np.mean(y_mins), np.mean(x_max), np.mean(y_max)]
|
||||
|
||||
|
||||
def intersects_any(box_a, boxes):
|
||||
for box in boxes:
|
||||
if box_overlaps(box_a, box):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user