|
@@ -31,12 +31,12 @@ from config import (
|
|
|
DETECTION_CONFIG, PTZ_CONFIG, COORDINATOR_CONFIG,
|
|
DETECTION_CONFIG, PTZ_CONFIG, COORDINATOR_CONFIG,
|
|
|
CALIBRATION_CONFIG, LOG_CONFIG, SYSTEM_CONFIG,
|
|
CALIBRATION_CONFIG, LOG_CONFIG, SYSTEM_CONFIG,
|
|
|
CAMERA_GROUPS, get_enabled_groups,
|
|
CAMERA_GROUPS, get_enabled_groups,
|
|
|
- TRACKING_CONFIG,
|
|
|
|
|
|
|
+ TRACKING_CONFIG, EVENT_PUSHER_CONFIG,
|
|
|
)
|
|
)
|
|
|
from dahua_sdk import DahuaSDK
|
|
from dahua_sdk import DahuaSDK
|
|
|
from panorama_camera import PanoramaCamera, ObjectDetector, DetectedObject
|
|
from panorama_camera import PanoramaCamera, ObjectDetector, DetectedObject
|
|
|
from ptz_camera import PTZCamera, PTZController
|
|
from ptz_camera import PTZCamera, PTZController
|
|
|
-from coordinator import Coordinator, EventDrivenCoordinator, AsyncCoordinator, SequentialCoordinator
|
|
|
|
|
|
|
+from coordinator import AsyncCoordinator, SequentialCoordinator
|
|
|
from tracker import UltralyticsTracker
|
|
from tracker import UltralyticsTracker
|
|
|
from polling_tracker import PollingTrackingCoordinator
|
|
from polling_tracker import PollingTrackingCoordinator
|
|
|
|
|
|
|
@@ -291,8 +291,19 @@ class DualCameraSystem:
|
|
|
self.detector
|
|
self.detector
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+ # 初始化事件推送器
|
|
|
|
|
+ enable_event_push = SYSTEM_CONFIG.get('enable_event_push', False)
|
|
|
|
|
+ if enable_event_push and not getattr(self, 'event_pusher', None):
|
|
|
|
|
+ try:
|
|
|
|
|
+ from event_pusher import EventPusher
|
|
|
|
|
+ self.event_pusher = EventPusher(EVENT_PUSHER_CONFIG)
|
|
|
|
|
+ logger.info("事件推送器初始化成功")
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ logger.warning(f"事件推送器初始化失败: {e}")
|
|
|
|
|
+ self.event_pusher = None
|
|
|
|
|
+
|
|
|
# 注入事件推送器
|
|
# 注入事件推送器
|
|
|
- if getattr(self, 'event_pusher', None) is not None and hasattr(self.coordinator, 'set_event_pusher'):
|
|
|
|
|
|
|
+ if self.event_pusher is not None and hasattr(self.coordinator, 'set_event_pusher'):
|
|
|
self.coordinator.set_event_pusher(self.event_pusher)
|
|
self.coordinator.set_event_pusher(self.event_pusher)
|
|
|
|
|
|
|
|
# 设置回调
|
|
# 设置回调
|
|
@@ -567,6 +578,9 @@ class DualCameraSystem:
|
|
|
self.running = True
|
|
self.running = True
|
|
|
logger.info("联动系统启动成功")
|
|
logger.info("联动系统启动成功")
|
|
|
|
|
|
|
|
|
|
+ if self.event_pusher is not None:
|
|
|
|
|
+ self.event_pusher.start()
|
|
|
|
|
+
|
|
|
# 启动定时校准
|
|
# 启动定时校准
|
|
|
self._start_periodic_calibration()
|
|
self._start_periodic_calibration()
|
|
|
|
|
|
|
@@ -591,7 +605,7 @@ class DualCameraSystem:
|
|
|
|
|
|
|
|
def get_results(self):
|
|
def get_results(self):
|
|
|
"""获取识别结果"""
|
|
"""获取识别结果"""
|
|
|
- if self.coordinator:
|
|
|
|
|
|
|
+ if self.coordinator and hasattr(self.coordinator, 'get_results'):
|
|
|
return self.coordinator.get_results()
|
|
return self.coordinator.get_results()
|
|
|
return []
|
|
return []
|
|
|
|
|
|
|
@@ -765,6 +779,9 @@ class DualCameraSystem:
|
|
|
|
|
|
|
|
# 确保定时校准停止
|
|
# 确保定时校准停止
|
|
|
self._stop_periodic_calibration()
|
|
self._stop_periodic_calibration()
|
|
|
|
|
+
|
|
|
|
|
+ if self.event_pusher is not None:
|
|
|
|
|
+ self.event_pusher.stop()
|
|
|
|
|
|
|
|
if self.sdk:
|
|
if self.sdk:
|
|
|
self.sdk.cleanup()
|
|
self.sdk.cleanup()
|
|
@@ -819,19 +836,25 @@ def run_interactive(system: DualCameraSystem):
|
|
|
try:
|
|
try:
|
|
|
coords = input("输入坐标 (x y, 范围0-1): ").strip().split()
|
|
coords = input("输入坐标 (x y, 范围0-1): ").strip().split()
|
|
|
x, y = float(coords[0]), float(coords[1])
|
|
x, y = float(coords[0]), float(coords[1])
|
|
|
- system.coordinator.force_track_position(x, y)
|
|
|
|
|
- print(f"已移动到位置 ({x:.2f}, {y:.2f})")
|
|
|
|
|
|
|
+ if hasattr(system.coordinator, 'force_track_position'):
|
|
|
|
|
+ system.coordinator.force_track_position(x, y)
|
|
|
|
|
+ print(f"已移动到位置 ({x:.2f}, {y:.2f})")
|
|
|
|
|
+ else:
|
|
|
|
|
+ print("当前模式不支持手动跟踪")
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
print(f"输入错误: {e}")
|
|
print(f"输入错误: {e}")
|
|
|
|
|
|
|
|
elif cmd == 'c':
|
|
elif cmd == 'c':
|
|
|
- frame = system.coordinator.capture_snapshot()
|
|
|
|
|
- if frame is not None:
|
|
|
|
|
- filename = f"snapshot_{int(time.time())}.jpg"
|
|
|
|
|
- cv2.imwrite(filename, frame)
|
|
|
|
|
- print(f"快照已保存: {filename}")
|
|
|
|
|
|
|
+ if hasattr(system.coordinator, 'capture_snapshot'):
|
|
|
|
|
+ frame = system.coordinator.capture_snapshot()
|
|
|
|
|
+ if frame is not None:
|
|
|
|
|
+ filename = f"snapshot_{int(time.time())}.jpg"
|
|
|
|
|
+ cv2.imwrite(filename, frame)
|
|
|
|
|
+ print(f"快照已保存: {filename}")
|
|
|
|
|
+ else:
|
|
|
|
|
+ print("抓拍失败")
|
|
|
else:
|
|
else:
|
|
|
- print("抓拍失败")
|
|
|
|
|
|
|
+ print("当前模式不支持抓拍")
|
|
|
|
|
|
|
|
elif cmd == 'b':
|
|
elif cmd == 'b':
|
|
|
print("开始手动校准...")
|
|
print("开始手动校准...")
|