{"record":{"id":"f0c7ab959afe8f03","repo":"roboflow/supervision","slug":"kernel-size-must-be-1-got-kernel-size","errorCode":null,"errorMessage":"kernel_size must be >= 1, got {kernel_size}.","messagePattern":"kernel_size must be >= 1, got (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/annotators/core.py","lineNumber":2050,"sourceCode":"        return _load_icon_from_path(\n            icon_path=icon_path, icon_resolution_wh=self.icon_resolution_wh\n        )\n\n\nclass BlurAnnotator(BaseAnnotator):\n    \"\"\"\n    A class for blurring regions in an image using provided detections.\n    \"\"\"\n\n    def __init__(self, kernel_size: int | None = None):\n        \"\"\"\n        Args:\n            kernel_size: The size of the average pooling kernel used for blurring.\n                If not set, a dynamic size is computed as one-third of the shorter\n                bounding-box dimension. Must be >= 1 when provided.\n        \"\"\"\n        if kernel_size is not None and kernel_size < 1:\n            raise ValueError(f\"kernel_size must be >= 1, got {kernel_size}.\")\n        self.kernel_size: int | None = kernel_size\n\n    @ensure_cv2_image_for_class_method\n    def annotate(\n        self,\n        scene: ImageType,\n        detections: Detections,\n    ) -> ImageType:\n        \"\"\"\n        Annotates the given scene by blurring regions based on the provided detections.\n\n        Args:\n            scene: The image where blurring will be applied.\n                `ImageType` is a flexible type, accepting either `numpy.ndarray`\n                or `PIL.Image.Image`.\n            detections: Object detections to annotate.\n\n        Returns:","sourceCodeStart":2032,"sourceCodeEnd":2068,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/annotators/core.py#L2032-L2068","documentation":"Raised by `BlurAnnotator.__init__` when an explicit `kernel_size` smaller than 1 is passed. The kernel drives OpenCV average pooling; a zero or negative size is invalid for OpenCV and meaningless for blurring, so it is rejected at construction time rather than crashing later inside cv2.","triggerScenarios":"Calling `sv.BlurAnnotator(kernel_size=0)` or `kernel_size=-3`; computing kernel size from a config or box dimension as `int(smallest_side * ratio)` where rounding or a small ratio yields 0; passing None is fine (dynamic sizing) — only explicit values < 1 raise.","commonSituations":"Auto-tuned blur strength from image dimensions that floors to 0 for tiny images; config files with a missing/zero blur setting; unit tests sweeping parameter values including 0.","solutions":["Pass `kernel_size=None` to let the annotator compute a dynamic size from each box.","Use `kernel_size=max(1, computed_value)` when deriving the size from measurements.","Fix the config value to a positive odd/positive integer such as 15 or 25."],"exampleFix":"# before\nkernel = int(min(w, h) * 0.05)  # tiny box -> 0\nannotator = sv.BlurAnnotator(kernel_size=kernel)  # ValueError\n\n# after\nkernel = max(1, int(min(w, h) * 0.05))\nannotator = sv.BlurAnnotator(kernel_size=kernel if kernel > 0 else None)","handlingStrategy":"validation","validationCode":"kernel_size = None if computed_size is None else max(1, int(computed_size))\nannotator = sv.BlurAnnotator(kernel_size=kernel_size)","typeGuard":"def is_valid_kernel_size(v) -> bool:\n    return v is None or (isinstance(v, int) and v >= 1)","tryCatchPattern":null,"preventionTips":["Pass kernel_size=None for automatic sizing.","Clamp derived sizes with max(1, ...) instead of trusting arithmetic."],"tags":["annotators","blur","validation"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}