Files
HVideoTool/hvideotool/core/detection/factory.py
T

30 lines
1.0 KiB
Python

"""Detector factory: build a Detector from AppConfig.
Kept separate from ``app.py`` so both the app bootstrap and the UI can build
detectors without an import cycle. Raises ``ValueError`` (not ``SystemExit``) on
bad config so the GUI can show the message instead of exiting.
Only the YOLO detector is supported — the classic-CV heuristic (and the composite
mode that combined them) were removed: they were noisy/approximate on real footage.
"""
from __future__ import annotations
from ...config import AppConfig
from .base import Detector
def _require_model(config: AppConfig) -> str:
if not config.model_path:
raise ValueError(
"Для детектора YOLO укажите путь к весам (.pt) в Параметрах "
"или скачайте модель LADA — см. README."
)
return config.model_path
def build_detector(config: AppConfig) -> Detector:
from .yolo import YoloDetector # lazy: pulls torch/ultralytics
return YoloDetector(_require_model(config), config.detection)