use enum in config for zooming

This commit is contained in:
Josh Hawkins 2023-09-06 09:08:48 -05:00
parent 1f624d3c6c
commit 7117daa782
4 changed files with 36 additions and 25 deletions

View File

@ -50,10 +50,12 @@ cameras:
autotracking:
# Optional: enable/disable object autotracking. (default: shown below)
enabled: False
# Optional: enable/disable camera zooming in/out on objects during autotracking. (default: shown below)
zooming: False
# Optional: enable/disable relative zooming for the camera (default: shown below)
zoom_relative: False
# Optional: the mode to use for zooming in/out on objects during autotracking. (default: shown below)
# Available options are: disabled, absolute, and relative
# disabled - don't zoom in/out on autotracked objects, use pan/tilt only
# absolute - use absolute zooming (supported by most PTZ capable cameras)
# relative - use relative zooming (not supported on all PTZs, but makes concurrent pan/tilt/zoom movements)
zooming: disabled
# Optional: list of objects to track from labelmap.txt (default: shown below)
track:
- person
@ -74,9 +76,13 @@ The object tracker in Frigate estimates the motion of the PTZ so that tracked ob
A fast [detector](object_detectors.md) is recommended. CPU detectors will not perform well or won't work at all. If your PTZ's motor is slow, you may not be able to reliably autotrack fast moving objects or objects close to the camera.
# Zooming
Zooming is an experimental feature and may use significantly more CPU when tracking objects than panning/tilting only. It may be helpful to tweak your camera's autofocus settings if you are noticing focus problems when using zooming.
Relative zooming makes a zoom movement concurrently with any pan/tilt movements and was tested to work with some Dahua and Amcrest PTZs. If zooming behavior is erratic or relative zooming is unsupported, the autotracker will fall back to absolute zooming and make zoom movements separate from pan/tilt movements.
Absolute zooming makes zoom movements separate from pan/tilt movements. Most PTZ cameras will support absolute zooming.
Relative zooming attempts to make a zoom movement concurrently with any pan/tilt movements. It was tested to work with some Dahua and Amcrest PTZs. But the ONVIF specification indicates that there no assumption about how the generic zoom range is mapped to magnification, field of view or other physical zoom dimension when using relative zooming. So if relative zooming behavior is erratic or just doesn't work, use absolute zooming.
## Usage applications

View File

@ -573,10 +573,12 @@ cameras:
autotracking:
# Optional: enable/disable object autotracking. (default: shown below)
enabled: False
# Optional: enable/disable camera zooming in/out on objects during autotracking. (default: shown below)
zooming: False
# Optional: enable/disable relative zooming for the camera (default: shown below)
zoom_relative: False
# Optional: the mode to use for zooming in/out on objects during autotracking. (default: shown below)
# Available options are: disabled, absolute, and relative
# disabled - don't zoom in/out on autotracked objects, use pan/tilt only
# absolute - use absolute zooming (supported by most PTZ capable cameras)
# relative - use relative zooming (not supported on all PTZs, but makes concurrent pan/tilt/zoom movements)
zooming: disabled
# Optional: list of objects to track from labelmap.txt (default: shown below)
track:
- person

View File

@ -137,12 +137,15 @@ class MqttConfig(FrigateBaseModel):
return v
class ZoomingModeEnum(str, Enum):
disabled = "disabled"
absolute = "absolute"
relative = "relative"
class PtzAutotrackConfig(FrigateBaseModel):
enabled: bool = Field(default=False, title="Enable PTZ object autotracking.")
zooming: bool = Field(default=False, title="Enable zooming on autotracked object.")
zoom_relative: bool = Field(
default=False, title="Use relative zooming instead of absolute."
)
zooming: ZoomingModeEnum = Field(default=ZoomingModeEnum.disabled, title="Autotracker zooming mode.")
track: List[str] = Field(default=DEFAULT_TRACKED_OBJECTS, title="Objects to track.")
required_zones: List[str] = Field(
default_factory=list,

View File

@ -17,7 +17,7 @@ from norfair.camera_motion import (
TranslationTransformationGetter,
)
from frigate.config import CameraConfig, FrigateConfig
from frigate.config import CameraConfig, FrigateConfig, ZoomingModeEnum
from frigate.ptz.onvif import OnvifController
from frigate.types import PTZMetricsTypes
from frigate.util.image import SharedMemoryFrameManager, intersection_over_union
@ -60,7 +60,10 @@ class PtzMotionEstimator:
self.ptz_metrics["ptz_reset"].clear()
# homography is nice (zooming) but slow, translation is pan/tilt only but fast.
if self.camera_config.onvif.autotracking.zooming:
if (
self.camera_config.onvif.autotracking.zooming
!= ZoomingModeEnum.disabled
):
logger.debug("Motion estimator reset - homography")
transformation_type = HomographyTransformationGetter()
else:
@ -109,7 +112,10 @@ class PtzMotionEstimator:
self.frame_manager.close(frame_id)
if not self.camera_config.onvif.autotracking.zooming:
if (
self.camera_config.onvif.autotracking.zooming
== ZoomingModeEnum.disabled
):
# doesn't work with homography
logger.debug(
f"Motion estimator transformation: {self.coord_transformations.rel_to_abs((0,0))}"
@ -234,7 +240,7 @@ class PtzAutoTracker:
else:
if (
self.config.cameras[camera].onvif.autotracking.zooming
and self.config.cameras[camera].onvif.autotracking.zoom_relative
== ZoomingModeEnum.relative
):
self.onvif._move_relative(camera, pan, tilt, zoom, 1)
else:
@ -305,10 +311,7 @@ class PtzAutoTracker:
tilt = (0.5 - (obj.obj_data["centroid"][1] / camera_height)) * 2
# ideas: check object velocity for camera speed?
if (
camera_config.onvif.autotracking.zooming
and camera_config.onvif.autotracking.zoom_relative
):
if camera_config.onvif.autotracking.zooming == ZoomingModeEnum.relative:
# relative zooming concurrently with pan/tilt
zoom = obj.obj_data["area"] / (camera_width * camera_height)
@ -333,10 +336,7 @@ class PtzAutoTracker:
camera_config = self.config.cameras[camera]
# absolute zooming separately from pan/tilt
if (
camera_config.onvif.autotracking.zooming
and not camera_config.onvif.autotracking.zoom_relative
):
if camera_config.onvif.autotracking.zooming == ZoomingModeEnum.absolute:
zoom_level = self.ptz_metrics[camera]["ptz_zoom_level"].value
if 0 < zoom_level <= 1: