mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-18 17:14:26 +03:00
check autotracking calibration values before writing to config
This commit is contained in:
parent
15ffe5c254
commit
6851b712f8
@ -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
|
||||
|
||||
|
||||
@ -500,9 +500,26 @@ 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")
|
||||
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:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user