"""Classic inpainting restorer (cv2) — the always-available baseline. HONEST LIMITATION: cv2 inpainting fills the masked region by propagating surrounding pixels. It removes the mosaic/bar but does NOT reconstruct the hidden detail — it smooths/guesses. For real reconstruction a generative model (DeepMosaics / LADA) is needed; this is the no-weights, no-GPU fallback so the "Расцензурить кадр" flow works end-to-end today. """ from __future__ import annotations import cv2 import numpy as np from ..detection.types import Detection from .base import CancelCheck, Restorer from .mask import detections_to_mask class InpaintRestorer(Restorer): def __init__(self, radius: int = 3, dilate: int = 2, method: str = "telea") -> None: self.radius = radius self.dilate = dilate self.method = method @property def name(self) -> str: return f"InpaintRestorer({self.method})" def restore( self, image: np.ndarray, detections: list[Detection], should_cancel: CancelCheck | None = None, ) -> np.ndarray: # Single cv2.inpaint call — effectively instant, so cancellation is moot. if not detections: return image.copy() mask = detections_to_mask(image.shape, detections, dilate=self.dilate) flags = cv2.INPAINT_TELEA if self.method == "telea" else cv2.INPAINT_NS return cv2.inpaint(image, mask, self.radius, flags)