detector_service.py 627 B

123456789101112131415161718
  1. """复用现有 ObjectDetector 的薄封装."""
  2. import threading
  3. from config.detection import DETECTION_CONFIG
  4. from panorama_camera import ObjectDetector
  5. class DetectorService:
  6. def __init__(self, model_path: str = None, use_gpu: bool = None):
  7. model_path = model_path or DETECTION_CONFIG.get("model_path")
  8. if use_gpu is None:
  9. use_gpu = DETECTION_CONFIG.get("use_gpu", True)
  10. self.detector = ObjectDetector(model_path=model_path, use_gpu=use_gpu)
  11. self._lock = threading.Lock()
  12. def detect(self, frame):
  13. with self._lock:
  14. return self.detector.detect(frame)