Refactor HVideoTool to exclusively use YOLO for detection and DeepMosaics for restoration: removed classic CV and composite detectors, updated configuration and UI accordingly. Enhanced documentation in README and CLAUDE.md to reflect these changes, including new batch processing capabilities and device diagnostics.

This commit is contained in:
Leonid Pershin
2026-06-07 06:16:05 +03:00
parent cc518cc3e6
commit 9c471ca701
17 changed files with 798 additions and 676 deletions
+21 -27
View File
@@ -1,40 +1,21 @@
"""Application configuration and tunable defaults.
Plain dataclasses. The detection thresholds matter most here — this tool is now
an image-folder inspector for tuning the detectors, so keep them easy to tweak.
Plain dataclasses. Detection is YOLO-only and restoration is DeepMosaics-only, so the
knobs here are the YOLO inference params, the overlay style, and the DeepMosaics weights.
"""
from __future__ import annotations
from dataclasses import dataclass, field
DETECTORS = ("yolo",)
RESTORERS = ("deepmosaics", "deepmosaics_video")
@dataclass(frozen=True)
class DetectionConfig:
"""Parameters for the detector. Thresholds tuned for the classic-CV detector."""
"""Parameters for the YOLO detector."""
proc_max_dim: int = 720 # downscale longer side to this before detection (speed)
min_area_frac: float = 0.0008 # ignore regions smaller than this fraction of the image
# --- solid bars (black or white, achromatic, rectangular) ---
black_intensity: int = 40 # V below this = dark-bar candidate
white_intensity: int = 225 # V above this = light-bar candidate
bar_saturation_max: int = 45 # S below this = achromatic (excludes colored fills)
bar_min_extent: float = 0.80 # contour area / bbox area — how rectangular a bar must be
# --- mosaic / pixelation ---
mosaic_block_sizes: tuple[int, ...] = (8, 12, 16, 24) # candidate tile sizes (px, proc space)
mosaic_residual_max: float = 6.0 # max reconstruction error to count as "blocky"
mosaic_contrast_min: float = 14.0 # min local contrast (excludes flat gradients)
mosaic_grad_min: float = 8.0 # min edge energy in BOTH x and y (excludes straight edges)
mosaic_min_side: int = 24 # reject thin regions (px) — kills edge false-positives
# --- blur ---
blur_window: int = 31 # sliding window for local sharpness (odd)
blur_sharpness_ratio: float = 0.35 # below this fraction of median sharpness => blurry
blur_contrast_min: float = 8.0 # min local contrast (excludes flat regions)
# --- YOLO detector (used only when detector == "yolo"/"combined") ---
yolo_conf: float = 0.2 # confidence threshold (LADA recommends ~0.2)
yolo_imgsz: int = 640 # inference image size
yolo_device: str | None = None # None => auto ("cuda" if available, else "cpu")
@@ -62,13 +43,26 @@ class OverlayConfig:
class AppConfig:
detection: DetectionConfig = field(default_factory=DetectionConfig)
overlay: OverlayConfig = field(default_factory=OverlayConfig)
detector: str = "classic" # "classic" | "yolo" | "combined"
detector: str = "yolo" # only "yolo"
model_path: str | None = None # weights path, used by the YOLO detector
default_threshold: float = 0.20 # initial overlay confidence threshold
# --- restoration ("расцензурить") ---
restorer: str = "inpaint" # "inpaint" | "deepmosaics"
restorer: str = "deepmosaics" # "deepmosaics" | "deepmosaics_video"
dm_dir: str | None = None # DeepMosaics repo dir (contains deepmosaic.py)
dm_model: str | None = None # DeepMosaics clean weights (clean_*.pth)
dm_python: str | None = None # python exe for DeepMosaics (None = current)
dm_gpu: str = "0" # CUDA device id, "-1" for CPU
def normalize_config(cfg: AppConfig) -> None:
"""Coerce legacy/removed settings to supported values (mutates ``cfg``).
Old projects / settings.json may carry the removed ``classic``/``combined``
detectors or the ``inpaint`` restorer — map those onto the survivors so loading
them doesn't blow up at build time.
"""
if cfg.detector not in DETECTORS:
cfg.detector = "yolo"
if cfg.restorer not in RESTORERS:
cfg.restorer = "deepmosaics"