Autotracking optimizations (#7109)

* much improved motion estimation and tracking

* docs updates

* move ptz specific mp values to ptz_metrics dict

* only check if moving at frame time

* pass full dict instead of individual values
This commit is contained in:
Josh Hawkins
2023-07-11 06:23:20 -05:00
committed by GitHub
parent a94346e17e
commit 7a2d09dc35
8 changed files with 188 additions and 97 deletions

View File

@@ -8,6 +8,7 @@ from norfair.drawing.drawer import Drawer
from frigate.config import CameraConfig
from frigate.ptz.autotrack import PtzMotionEstimator
from frigate.track import ObjectTracker
from frigate.types import PTZMetricsTypes
from frigate.util.image import intersection_over_union
@@ -55,15 +56,18 @@ def frigate_distance(detection: Detection, tracked_object) -> float:
class NorfairTracker(ObjectTracker):
def __init__(self, config: CameraConfig, ptz_autotracker_enabled, ptz_stopped):
def __init__(
self,
config: CameraConfig,
ptz_metrics: PTZMetricsTypes,
):
self.tracked_objects = {}
self.disappeared = {}
self.positions = {}
self.max_disappeared = config.detect.max_disappeared
self.camera_config = config
self.detect_config = config.detect
self.ptz_autotracker_enabled = ptz_autotracker_enabled.value
self.ptz_stopped = ptz_stopped
self.ptz_autotracker_enabled = ptz_metrics["ptz_autotracker_enabled"]
self.camera_name = config.name
self.track_id_map = {}
# TODO: could also initialize a tracker per object class if there
@@ -74,8 +78,8 @@ class NorfairTracker(ObjectTracker):
initialization_delay=0,
hit_counter_max=self.max_disappeared,
)
if self.ptz_autotracker_enabled:
self.ptz_motion_estimator = PtzMotionEstimator(config, self.ptz_stopped)
if self.ptz_autotracker_enabled.value:
self.ptz_motion_estimator = PtzMotionEstimator(config, ptz_metrics)
def register(self, track_id, obj):
rand_id = "".join(random.choices(string.ascii_lowercase + string.digits, k=6))
@@ -239,7 +243,7 @@ class NorfairTracker(ObjectTracker):
coord_transformations = None
if self.ptz_autotracker_enabled:
if self.ptz_autotracker_enabled.value:
coord_transformations = self.ptz_motion_estimator.motion_estimator(
detections, frame_time, self.camera_name
)