Add autotracking calibration message (#16431)

* check autotracking calibration values before writing to config

* docs

* clarify log message
This commit is contained in:
Josh Hawkins
2025-02-09 14:29:08 -07:00
committed by GitHub
parent cc2dbdcb44
commit 83beacf84a
3 changed files with 29 additions and 4 deletions
+3 -1
View File
@@ -64,7 +64,9 @@ class PtzAutotrackConfig(FrigateBaseModel):
raise ValueError("Invalid type for movement_weights")
if len(weights) != 5:
raise ValueError("movement_weights must have exactly 5 floats")
raise ValueError(
"movement_weights must have exactly 5 floats, remove this line from your config and run autotracking calibration"
)
return weights
+22 -3
View File
@@ -500,9 +500,28 @@ class PtzAutoTracker:
# simple linear regression with intercept
X_with_intercept = np.column_stack((np.ones(X.shape[0]), X))
self.move_coefficients[camera] = np.linalg.lstsq(
X_with_intercept, y, rcond=None
)[0]
coefficients = np.linalg.lstsq(X_with_intercept, y, rcond=None)[0]
intercept, slope = coefficients
# Define reasonable bounds for PTZ movement times
MIN_MOVEMENT_TIME = 0.1 # Minimum time for any movement (100ms)
MAX_MOVEMENT_TIME = 10.0 # Maximum time for any movement
MAX_SLOPE = 2.0 # Maximum seconds per unit of movement
coefficients_valid = (
MIN_MOVEMENT_TIME <= intercept <= MAX_MOVEMENT_TIME
and 0 < slope <= MAX_SLOPE
)
if not coefficients_valid:
logger.warning(
f"{camera}: Autotracking calibration failed. See the Frigate documentation."
)
return False
# If coefficients are valid, proceed with updates
self.move_coefficients[camera] = coefficients
# only assign a new intercept if we're calibrating
if calibration: