From c389d832b2d70b952f92ecaa3a12214e31bb6129 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Thu, 28 Sep 2023 08:50:22 -0500 Subject: [PATCH] check euclidean distance of estimate points --- frigate/ptz/autotrack.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/frigate/ptz/autotrack.py b/frigate/ptz/autotrack.py index 035c22d2d..73ef9ed93 100644 --- a/frigate/ptz/autotrack.py +++ b/frigate/ptz/autotrack.py @@ -532,12 +532,19 @@ class PtzAutoTracker: (y1 + y2) / 2, ) - # this box could exceed the frame boundaries if velocity is high - # but we'll handle that in _enqueue_move() as two separate moves - predicted_box = [ - round(x + camera_fps * predicted_movement_time * v) - for x, v in zip(obj.obj_data["box"], average_velocity) - ] + # get euclidean distance of the two points, sometimes the estimate is way off + distance = np.linalg.norm([x2 - x1, y2 - y1]) + + if distance <= 5: + # this box could exceed the frame boundaries if velocity is high + # but we'll handle that in _enqueue_move() as two separate moves + predicted_box = [ + round(x + camera_fps * predicted_movement_time * v) + for x, v in zip(obj.obj_data["box"], average_velocity) + ] + else: + # estimate was bad + predicted_box = obj.obj_data["box"] centroid_x = round((predicted_box[0] + predicted_box[2]) / 2) centroid_y = round((predicted_box[1] + predicted_box[3]) / 2)