From 614099c83fc1849f58b8015e6d09e9272a3cd7e3 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Thu, 28 Sep 2023 09:05:49 -0500 Subject: [PATCH] use numpy for euclidean distance --- frigate/ptz/autotrack.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frigate/ptz/autotrack.py b/frigate/ptz/autotrack.py index 73ef9ed93..bd46558dc 100644 --- a/frigate/ptz/autotrack.py +++ b/frigate/ptz/autotrack.py @@ -2,7 +2,6 @@ import copy import logging -import math import os import queue import threading @@ -656,10 +655,11 @@ class PtzAutoTracker: # more often to keep the object in the center. Raising the percentage will cause less # movement and will be more flexible with objects not quite being centered. # TODO: there's probably a better way to approach this - distance = math.sqrt( - (obj.obj_data["centroid"][0] - camera_config.detect.width / 2) ** 2 - + (obj.obj_data["centroid"][1] - camera_config.detect.height / 2) - ** 2 + distance = np.linalg.norm( + [ + obj.obj_data["centroid"][0] - camera_config.detect.width / 2, + obj.obj_data["centroid"][1] - camera_config.detect.height / 2, + ] ) obj_width = obj.obj_data["box"][2] - obj.obj_data["box"][0]