Autotracking fixes (#7096)

* only check camera status if autotracking enabled

* a more sensible sleep time

* Only check camera status if preparing for a move

* only update tracked obj position when ptz stopped

* both pantilt *and* zoom should be idle

* check more often after moving

* No need to move pan and tilt separately
This commit is contained in:
Josh Hawkins 2023-07-08 16:02:54 -05:00 committed by GitHub
parent f37f034b6a
commit 691e9d26d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 15 deletions

View File

@ -98,13 +98,12 @@ class PtzAutoTrackerThread(threading.Thread):
for camera_name, cam in self.config.cameras.items(): for camera_name, cam in self.config.cameras.items():
if cam.onvif.autotracking.enabled: if cam.onvif.autotracking.enabled:
self.ptz_autotracker.camera_maintenance(camera_name) self.ptz_autotracker.camera_maintenance(camera_name)
time.sleep(1)
else: else:
# disabled dynamically by mqtt # disabled dynamically by mqtt
if self.ptz_autotracker.tracked_object.get(camera_name): if self.ptz_autotracker.tracked_object.get(camera_name):
self.ptz_autotracker.tracked_object[camera_name] = None self.ptz_autotracker.tracked_object[camera_name] = None
self.ptz_autotracker.tracked_object_previous[camera_name] = None self.ptz_autotracker.tracked_object_previous[camera_name] = None
time.sleep(0.1) time.sleep(1)
logger.info("Exiting autotracker...") logger.info("Exiting autotracker...")
@ -199,11 +198,20 @@ class PtzAutoTracker:
move_data = self.move_queues[camera].get() move_data = self.move_queues[camera].get()
pan, tilt = move_data pan, tilt = move_data
self.onvif._move_relative(camera, pan, tilt, 1) # check if ptz is moving
self.onvif.get_camera_status(camera)
# Wait until the camera finishes moving # Wait until the camera finishes moving
self.camera_metrics[camera]["ptz_stopped"].wait() self.camera_metrics[camera]["ptz_stopped"].wait()
self.onvif._move_relative(camera, pan, tilt, 1)
# Wait until the camera finishes moving
while not self.camera_metrics[camera]["ptz_stopped"].is_set():
# check if ptz is moving
self.onvif.get_camera_status(camera)
time.sleep(1 / (self.config.cameras[camera].detect.fps / 2))
except queue.Empty: except queue.Empty:
time.sleep(0.1) time.sleep(0.1)
@ -229,10 +237,10 @@ class PtzAutoTracker:
def autotrack_object(self, camera, obj): def autotrack_object(self, camera, obj):
camera_config = self.config.cameras[camera] camera_config = self.config.cameras[camera]
# check if ptz is moving if (
self.onvif.get_camera_status(camera) camera_config.onvif.autotracking.enabled
and self.camera_metrics[camera]["ptz_stopped"].is_set()
if camera_config.onvif.autotracking.enabled: ):
# either this is a brand new object that's on our camera, has our label, entered the zone, is not a false positive, # either this is a brand new object that's on our camera, has our label, entered the zone, is not a false positive,
# and is not initially motionless - or one we're already tracking, which assumes all those things are already true # and is not initially motionless - or one we're already tracking, which assumes all those things are already true
if ( if (

View File

@ -247,14 +247,7 @@ class OnvifController:
"Zoom": 0, "Zoom": 0,
} }
# move pan and tilt separately
move_request.Translation.PanTilt.x = pan move_request.Translation.PanTilt.x = pan
move_request.Translation.PanTilt.y = 0
move_request.Translation.Zoom.x = 0
onvif.get_service("ptz").RelativeMove(move_request)
move_request.Translation.PanTilt.x = 0
move_request.Translation.PanTilt.y = tilt move_request.Translation.PanTilt.y = tilt
move_request.Translation.Zoom.x = 0 move_request.Translation.Zoom.x = 0
@ -350,7 +343,7 @@ class OnvifController:
status_request = self.cams[camera_name]["status_request"] status_request = self.cams[camera_name]["status_request"]
status = onvif.get_service("ptz").GetStatus(status_request) status = onvif.get_service("ptz").GetStatus(status_request)
if status.MoveStatus.PanTilt == "IDLE" or status.MoveStatus.Zoom == "IDLE": if status.MoveStatus.PanTilt == "IDLE" and status.MoveStatus.Zoom == "IDLE":
self.cams[camera_name]["active"] = False self.cams[camera_name]["active"] = False
self.camera_metrics[camera_name]["ptz_stopped"].set() self.camera_metrics[camera_name]["ptz_stopped"].set()
else: else: