{"record":{"id":"9e31c0ed9d98aeac","repo":"roboflow/supervision","slug":"unsupported-interpolation-mode-interpolation","errorCode":null,"errorMessage":"Unsupported interpolation mode: {interpolation}","messagePattern":"Unsupported interpolation mode: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/_cv2/_image.py","lineNumber":157,"sourceCode":"    source_height, source_width = src.shape[:2]\n    width, height = dsize if dsize is not None else (0, 0)\n    if width == 0 or height == 0:\n        width = round(source_width * fx)\n        height = round(source_height * fy)\n    if min(width, height, source_width, source_height) <= 0:\n        raise ValueError(\"Resize dimensions must be positive\")\n\n    if interpolation == _INTER_NEAREST:\n        y_indices = np.minimum(\n            (np.arange(height) * source_height // height), source_height - 1\n        )\n        x_indices = np.minimum(\n            (np.arange(width) * source_width // width), source_width - 1\n        )\n        return np.ascontiguousarray(src[y_indices[:, np.newaxis], x_indices])\n\n    if interpolation != _INTER_LINEAR:\n        raise ValueError(f\"Unsupported interpolation mode: {interpolation}\")\n\n    if src.dtype == np.uint8 and (\n        src.ndim == 2 or (src.ndim == 3 and src.shape[2] == 3)\n    ):\n        from PIL import Image\n\n        size = (width, height)\n        image = Image.fromarray(src)\n        if width >= source_width and height >= source_height:\n            resized = image.resize(size, resample=Image.Resampling.BILINEAR)\n        else:\n            # Affine sampling keeps Pillow from widening its bilinear kernel\n            # during reduction and maps pixel centers like INTER_LINEAR.\n            resized = image.transform(\n                size,\n                Image.Transform.AFFINE,\n                (source_width / width, 0, 0, 0, source_height / height, 0),\n                resample=Image.Resampling.BILINEAR,","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/_cv2/_image.py#L139-L175","documentation":"The fallback resize implements only two interpolation modes: INTER_NEAREST (index-based gather) and INTER_LINEAR (Pillow bilinear or NumPy affine sampling). Any other cv2 interpolation constant (INTER_CUBIC, INTER_AREA, INTER_LANCZOS4, etc.) is rejected rather than silently approximated.","triggerScenarios":"Calling cv2.resize(..., interpolation=cv2.INTER_AREA) or INTER_CUBIC/INTER_LANCZOS4/INTER_NEAREST_EXACT etc. while running on the Supervision OpenCV fallback.","commonSituations":"Code written against real OpenCV that uses INTER_AREA for downscaling (a common high-quality shrink idiom) or INTER_CUBIC for upscaling, then executed in an environment where opencv-python is not installed (slim Docker images, CI without cv2).","solutions":["Use cv2.INTER_LINEAR or cv2.INTER_NEAREST, the two supported modes.","Install opencv-python (or opencv-python-headless) so Supervision delegates to real cv2 and all modes work.","If you need another kernel, pre-resize with PIL/scipy yourself and skip the fallback path."],"exampleFix":"# before\nsmall = cv2.resize(frame, (w, h), interpolation=cv2.INTER_AREA)\n\n# after (fallback-compatible)\nsmall = cv2.resize(frame, (w, h), interpolation=cv2.INTER_LINEAR)","handlingStrategy":"validation","validationCode":"SUPPORTED = {cv2.INTER_NEAREST, cv2.INTER_LINEAR}\ninterp = interp if interp in SUPPORTED else cv2.INTER_LINEAR\nresized = cv2.resize(frame, (w, h), interpolation=interp)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Restrict resize calls to INTER_NEAREST/INTER_LINEAR in fallback environments","Install opencv-python when other kernels are required","Document the two-mode limitation in code that must run cv2-free"],"tags":["opencv-fallback","resize","interpolation","environment"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}